33template <const auto& caseTrueExpression, CompareOp op, is::constant Threshold, const auto& caseFalseExpression>
36 static constexpr auto& caseTrue = caseTrueExpression;
37 static constexpr auto& caseFalse = caseFalseExpression;
39 static constexpr auto compareOp = op;
41 using ThresholdValue = Threshold;
54namespace vctr::expressions
56template <
size_t extent,
class SrcType, is::binaryCaseDistinctionConfig CaseConfig>
67 using CaseTrueExpressionChainBuilder =
decltype (CaseConfig::caseTrue << std::declval<SrcType>());
68 using CaseFalseExpressionChainBuilder =
decltype (CaseConfig::caseFalse << std::declval<SrcType>());
70 CaseTrueExpressionChainBuilder caseTrue;
71 CaseFalseExpressionChainBuilder caseFalse;
73 static constexpr value_type threshold = CaseConfig::ThresholdValue::value;
79 : src (std::forward<Src>(s)),
80 caseTrue (CaseConfig::caseTrue << src),
81 caseFalse (CaseConfig::caseFalse << src)
84 VCTR_ASSERT (caseTrue.size() == src.size());
85 VCTR_ASSERT (caseFalse.size() == src.size());
88 constexpr const auto& getStorageInfo()
const
90 VCTR_ASSERT (&caseTrue.getStorageInfo() == &src.getStorageInfo());
91 VCTR_ASSERT (&caseFalse.getStorageInfo() == &src.getStorageInfo());
93 return src.getStorageInfo();
96 constexpr bool isNotAliased (
const void *other)
const
99 return caseTrue.isNotAliased (other) && caseFalse.isNotAliased (other) && src.isNotAliased (other);
102 constexpr size_t size()
const {
return src.size(); }
104 template<
size_t i,
class RuntimeArgs>
105 constexpr void iterateOverRuntimeArgChain(
const RuntimeArgs &rtArgs) {
106 tryApplyingRuntimeArgsToThisExpression<i>(rtArgs, *
this);
107 tryApplyingRuntimeArgsToSrc<i + 1>(rtArgs, src);
110 VCTR_FORCEDINLINE
constexpr value_type operator[] (
size_t i)
const
112 return scalarCompare<CaseConfig::compareOp> (src[i], threshold) ? caseTrue[i] : caseFalse[i];
117 VCTR_FORCEDINLINE VCTR_TARGET (
"avx")
void prepareAVXEvaluation()
const
120 src.prepareAVXEvaluation();
121 caseTrue.prepareAVXEvaluation();
122 caseFalse.prepareAVXEvaluation();
124 thresholdSIMDConst.avx = Expression::AVX::broadcast (threshold);
130 auto caseTrueResult = caseTrue.getAVX (i);
131 auto caseFalseResult = caseFalse.getAVX (i);
133 auto compareResult = Expression::AVX::template compare<CaseConfig::compareOp> (src.getAVX (i), thresholdSIMDConst.avx);
135 return Expression::AVX::bitwiseBlend (caseFalseResult, caseTrueResult, compareResult);
141 auto caseTrueResult = caseTrue.getAVX (i);
142 auto caseFalseResult = caseFalse.getAVX (i);
144 auto compareResult = Expression::AVX::template compare<CaseConfig::compareOp> (src.getAVX (i), thresholdSIMDConst.avx);
146 return Expression::AVX::bitwiseBlend (caseFalseResult, caseTrueResult, compareResult);
151 VCTR_FORCEDINLINE
void prepareNeonEvaluation()
const
154 src.prepareNeonEvaluation();
155 caseTrue.prepareNeonEvaluation();
156 caseFalse.prepareNeonEvaluation();
158 thresholdSIMDConst.neon = Expression::Neon::broadcast (threshold);
164 auto caseTrueResult = caseTrue.getNeon (i);
165 auto caseFalseResult = caseFalse.getNeon (i);
167 auto compareResult = Expression::Neon::template compare<CaseConfig::compareOp> (src.getNeon (i), thresholdSIMDConst.neon);
169 return Expression::Neon::bitwiseBlend (caseFalseResult, caseTrueResult, compareResult);
192template <const auto& caseTrueExpression, CompareOp compareOp, const auto& threshold, const auto& caseFalseExpression>
Definition: BinaryCaseDistinction.h:59
Constrains a type to have a member function getAVX (size_t) const.
Definition: ContainerAndExpressionConcepts.h:92
Constrains a type to have a member function getNeon (size_t) const.
Definition: ContainerAndExpressionConcepts.h:84
Constrains a type to have a member function prepareAVXEvaluation() const.
Definition: ContainerAndExpressionConcepts.h:88
Constrains a type to have a member function prepareNeonEvaluation() const.
Definition: ContainerAndExpressionConcepts.h:80
Constrains T to be any instance of BinaryCaseDistinctionConfig.
Definition: BinaryCaseDistinction.h:50
Constrains two instances of T to be comparable by the operation specified by op.
Definition: CompareOp.h:65
constexpr ExpressionChainBuilder< expressions::BinaryCaseDistinction, BinaryCaseDistinctionConfig< caseTrueExpression, compareOp, ConstantRef< threshold >, caseFalseExpression > > binaryCaseDistinction
Evaluates one of two expressions depending on a binary condition.
Definition: BinaryCaseDistinction.h:193
The main namespace of the VCTR project.
Definition: Array.h:24
typename detail::ValueType< std::remove_cvref_t< T > >::Type ValueType
If T is an expression template, it equals its return type, if it's a type that defines value_type as ...
Definition: Traits.h:201
CompareOp
Possible types of (SIMD) compare operations.
Definition: CompareOp.h:41
Definition: AVXRegister.h:28
Helper struct to pass multiple partly non-type template parameters to a BinaryCaseDistinction express...
Definition: BinaryCaseDistinction.h:35
An expression chain builder is an object which supplies various operator<< overloads which build chai...
Definition: ExpressionChainBuilder.h:170
Supplies some handy typedefs and traits needed when implementing expression templates.
Definition: ExpressionTemplate.h:41
The base class to every expression template.
Definition: ExpressionTemplate.h:37
Definition: NeonRegister.h:28
Helper template to define a union of all supported SIMD types.
Definition: ExpressionTemplate.h:123