23namespace vctr::expressions
26template <
size_t extent,
class SrcType, is::constantWithType<
bool> ClampLow, is::constantWithType<
bool> ClampHigh>
32 VCTR_COMMON_UNARY_EXPRESSION_MEMBERS (
Clamp, src)
34 static constexpr bool clampLow = ClampLow::value;
35 static constexpr bool clampHigh = ClampHigh::value;
37 constexpr void applyRuntimeArgs (value_type newLowerBound, value_type newUpperBound)
39 lowerBound = newLowerBound;
40 upperBound = newUpperBound;
43 VCTR_FORCEDINLINE
constexpr value_type operator[] (
size_t i)
const
48 return std::clamp (src[i], lowerBound, upperBound);
51 return std::max (src[i], lowerBound);
54 return std::min (src[i], upperBound);
59 VCTR_FORCEDINLINE
const value_type* evalNextVectorOpInExpressionChain (value_type* dst)
const
65 Expression::Accelerate::clampLow (src.evalNextVectorOpInExpressionChain (dst), lowerBound, dst, size());
69 auto l =
clampLow ? lowerBound : std::numeric_limits<value_type>::lowest();
70 Expression::Accelerate::clamp (src.evalNextVectorOpInExpressionChain (dst), l, upperBound, dst, size());
76 VCTR_FORCEDINLINE
const value_type* evalNextVectorOpInExpressionChain (value_type* dst)
const
80 const auto* s = src.evalNextVectorOpInExpressionChain (dst);
84 Expression::IPP::clampLow (s, lowerBound, dst,
sizeToInt (size()));
91 Expression::IPP::clampHigh (s, upperBound, dst,
sizeToInt (size()));
97 void assertBoundsAreSet()
const
102 VCTR_ASSERT (lowerBound != std::numeric_limits<value_type>::max());
105 VCTR_ASSERT (upperBound != std::numeric_limits<value_type>::max());
108 value_type lowerBound = std::numeric_limits<value_type>::max();
109 value_type upperBound = std::numeric_limits<value_type>::max();
112template <
size_t extent,
class SrcType>
115template <
size_t extent,
class SrcType>
118template <
size_t extent,
class SrcType>
121template <
size_t extent,
class SrcType, is::constant LowerBound, is::constant UpperBound>
127 static constexpr value_type lowerBound = LowerBound::value;
128 static constexpr value_type upperBound = UpperBound::value;
135 VCTR_FORCEDINLINE
constexpr value_type operator[] (
size_t i)
const
138 return std::clamp (src[i], lowerBound, upperBound);
141 return std::max (src[i], lowerBound);
144 return std::min (src[i], upperBound);
146 return std::max (lowerBound, src[i]);
151 VCTR_FORCEDINLINE VCTR_TARGET (
"avx")
void prepareAVXEvaluation()
const
154 src.prepareAVXEvaluation();
157 lowerBoundSIMD.avx = Expression::AVX::broadcast (lowerBound);
160 upperBoundSIMD.avx = Expression::AVX::broadcast (upperBound);
164 requires (archX64 &&
has::getAVX<SrcType> && Expression::allElementTypesSame && Expression::CommonElement::isRealFloat)
166 auto x = src.getAVX (i);
169 x = Expression::AVX::max (lowerBoundSIMD.avx, x);
172 x = Expression::AVX::min (x, upperBoundSIMD.avx);
179 VCTR_FORCEDINLINE VCTR_TARGET (
"sse4.1")
void prepareSSEEvaluation()
const
182 src.prepareSSEEvaluation();
185 lowerBoundSIMD.sse = Expression::SSE::broadcast (lowerBound);
188 upperBoundSIMD.sse = Expression::SSE::broadcast (upperBound);
192 requires (archX64 &&
has::getSSE<SrcType> && Expression::allElementTypesSame && Expression::CommonElement::isRealFloat)
194 auto x = src.getSSE (i);
197 x = Expression::SSE::max (lowerBoundSIMD.sse, x);
200 x = Expression::SSE::min (x, upperBoundSIMD.sse);
207 void prepareNeonEvaluation()
const
210 src.prepareNeonEvaluation();
213 lowerBoundSIMD.neon = Expression::Neon::broadcast (lowerBound);
216 upperBoundSIMD.neon = Expression::Neon::broadcast (upperBound);
220 requires (archARM &&
has::getNeon<SrcType> && Expression::allElementTypesSame && Expression::CommonElement::isRealFloat)
222 auto x = src.getNeon (i);
225 x = Expression::Neon::max (lowerBoundSIMD.neon, x);
228 x = Expression::Neon::min (x, upperBoundSIMD.neon);
235 VCTR_FORCEDINLINE
const value_type* evalNextVectorOpInExpressionChain (value_type* dst)
const
239 Expression::Accelerate::clampLow (src.evalNextVectorOpInExpressionChain (dst), lowerBound, dst, size());
243 auto l =
clampLow ? lowerBound : std::numeric_limits<value_type>::lowest();
244 Expression::Accelerate::clamp (src.evalNextVectorOpInExpressionChain (dst), l, upperBound, dst, size());
250 VCTR_FORCEDINLINE
const value_type* evalNextVectorOpInExpressionChain (value_type* dst)
const
253 const auto* s = src.evalNextVectorOpInExpressionChain (dst);
257 Expression::IPP::clampLow (s, lowerBound, dst,
sizeToInt (size()));
264 Expression::IPP::clampHigh (s, upperBound, dst,
sizeToInt (size()));
289 return makeExpressionChainBuilderWithRuntimeArgs<expressions::ClampLow> (lowerBound, std::numeric_limits<T>::max());
302 return makeExpressionChainBuilderWithRuntimeArgs<expressions::ClampHigh> (std::numeric_limits<T>::max(), upperBound);
313constexpr auto clamp (T lowerBound, T upperBound)
315 return makeExpressionChainBuilderWithRuntimeArgs<expressions::ClampLowHigh> (lowerBound, upperBound);
325template <is::range Range>
328 return makeExpressionChainBuilderWithRuntimeArgs<expressions::ClampLowHigh> (range.
getStart(), range.
getEnd());
340template <auto lowerBound>
351template <auto upperBound>
362template <auto lowerBound, auto upperBound>
369template <const auto& range>
A simple range class.
Definition: Range.h:32
constexpr ValueType getStart() const noexcept
Returns the start of the range.
Definition: Range.h:74
constexpr ValueType getEnd() const noexcept
Returns the end of the range.
Definition: Range.h:80
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 getSSE (size_t) const.
Definition: ContainerAndExpressionConcepts.h:100
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 a type to have a member function prepareSSEEvaluation() const.
Definition: ContainerAndExpressionConcepts.h:96
Constrains a type to be of the type DisabledConstant.
Definition: NumericTypeConcepts.h:99
Constrains the type to be a range, this is a class with a getStart, getLength and getEnd member funct...
Definition: GenericConcepts.h:125
A combined concept to check if Apple Accelerate is a suitable option for a real valued floating point...
Definition: ContainerAndExpressionConcepts.h:260
A combined concept to check if Intel IPP is a suitable option for a real valued floating point vector...
Definition: ContainerAndExpressionConcepts.h:284
constexpr ExpressionChainBuilder< expressions::ClampByConstant, DisabledConstant, Constant< upperBound > > clampHighByConstant
Ensures that the elements are not higher than upperBound.
Definition: Clamp.h:352
constexpr auto clampLow(T lowerBound)
Ensures that the elements are not lower than lowerBound.
Definition: Clamp.h:287
constexpr ExpressionChainBuilder< expressions::ClampByConstant, Constant< lowerBound >, Constant< upperBound > > clampByConstant
Ensures that the elements are not lower than lowerBound and not higher than upperBound.
Definition: Clamp.h:363
constexpr auto clampHigh(T upperBound)
Ensures that the elements are not greater than upperBound.
Definition: Clamp.h:300
constexpr ExpressionChainBuilder< expressions::ClampByConstant, Constant< lowerBound >, DisabledConstant > clampLowByConstant
Ensures that the elements are not lower than lowerBound.
Definition: Clamp.h:341
constexpr ExpressionChainBuilder< expressions::ClampByConstant, ConstantRangeStart< range >, ConstantRangeEnd< range > > clampToRange
Ensures that the elements are within the range.
Definition: Clamp.h:371
constexpr auto clamp(T lowerBound, T upperBound)
Ensures that the elements are not lower than lowerBound and not higher than upperBound.
Definition: Clamp.h:313
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
int sizeToInt(size_t size)
Casts the size_t argument to an int.
Definition: PlatformVectorOpsHelpers.h:27
Definition: AVXRegister.h:28
Evaluates the return value of getEnd called on the constant reference template argument and wraps tha...
Definition: ExpressionChainBuilder.h:124
Evaluates the return value of getStart called on the constant reference template argument and wraps t...
Definition: ExpressionChainBuilder.h:114
A helper struct to pass a constant as argument wrapped in a struct with a single public static conste...
Definition: ExpressionChainBuilder.h:104
A helper struct to indicate that a constant template should be considered disabled.
Definition: ExpressionChainBuilder.h:131
An expression chain builder is an object which supplies various operator<< overloads which build chai...
Definition: ExpressionChainBuilder.h:157
The base class to every expression template.
Definition: ExpressionTemplate.h:37
Definition: NeonRegister.h:28
Definition: SSERegister.h:28
Helper template to define a union of all supported SIMD types.
Definition: ExpressionTemplate.h:123