VCTR
Loading...
Searching...
No Matches
ElementwiseMax.h
1/*
2 ==============================================================================
3 DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
5 Copyright 2026 by sonible GmbH.
6
7 This file is part of VCTR - Versatile Container Templates Reconceptualized.
8
9 VCTR is free software: you can redistribute it and/or modify
10 it under the terms of the GNU Lesser General Public License version 3
11 only, as published by the Free Software Foundation.
12
13 VCTR is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU Lesser General Public License version 3 for more details.
17
18 You should have received a copy of the GNU Lesser General Public License
19 version 3 along with VCTR. If not, see <https://www.gnu.org/licenses/>.
20 ==============================================================================
21*/
22
23namespace vctr::expressions
24{
25template <size_t extent, class SrcAType, class SrcBType>
26requires std::totally_ordered_with<ValueType<SrcAType>, ValueType<SrcBType>>
28{
29public:
30 using value_type = std::common_type_t<ValueType<SrcAType>, ValueType<SrcBType>>;
31
32 VCTR_COMMON_BINARY_VEC_VEC_EXPRESSION_MEMBERS (ElementwiseMax, srcA, srcB)
33
34 VCTR_FORCEDINLINE constexpr auto operator[] (size_t i) const
35 {
36 return std::max (srcA[i], srcB[i]);
37 }
38
39 //==============================================================================
40 VCTR_FORWARD_PREPARE_SIMD_EVALUATION_BINARY_EXPRESSION_MEMBER_FUNCTIONS (srcA, srcB)
41
42 // AVX Implementation
43 VCTR_FORCEDINLINE VCTR_TARGET ("fma") AVXRegister<value_type> getAVX (size_t i) const
44 requires archX64 && has::getAVX<SrcAType> && has::getAVX<SrcBType> && Expression::CommonElement::isRealFloat
45 {
46 return Expression::AVX::max (srcA.getAVX (i), srcB.getAVX (i));
47 }
48
49 VCTR_FORCEDINLINE VCTR_TARGET ("avx2") AVXRegister<value_type> getAVX (size_t i) const
50 requires archX64 && has::getAVX<SrcAType> && has::getAVX<SrcBType> && (Expression::CommonElement::isInt32 || Expression::CommonElement::isUint32)
51 {
52 return Expression::AVX::max (srcA.getAVX (i), srcB.getAVX (i));
53 }
54
55 //==============================================================================
56 // SSE Implementation
57 VCTR_FORCEDINLINE VCTR_TARGET ("sse4.1") SSERegister<value_type> getSSE (size_t i) const
58 requires archX64 && has::getSSE<SrcAType> && has::getSSE<SrcBType> && (Expression::CommonElement::isRealFloat || Expression::CommonElement::isInt32 || Expression::CommonElement::isUint32)
59 {
60 return Expression::SSE::max (srcA.getSSE (i), srcB.getSSE (i));
61 }
62
63 //==============================================================================
64 // NEON Implementation
65 NeonRegister<value_type> getNeon (size_t i) const
66 requires archARM && has::getNeon<SrcAType> && has::getNeon<SrcBType> && (Expression::CommonElement::isRealFloat || Expression::CommonElement::isInt32 || Expression::CommonElement::isUint32)
67 {
68 return Expression::Neon::max (srcA.getNeon (i), srcB.getNeon (i));
69 }
70};
71
72} // namespace vctr::expressions
73
74namespace vctr
75{
76
78template <is::anyVctrOrExpression SrcAType, is::anyVctrOrExpression SrcBType>
79constexpr auto elementwiseMax (SrcAType&& a, SrcBType&& b)
80{
81 assertCommonSize (a, b);
82 constexpr auto extent = getCommonExtent<SrcAType, SrcBType>();
83
84 return expressions::ElementwiseMax<extent, SrcAType, SrcBType> (std::forward<SrcAType> (a), std::forward<SrcBType> (b));
85}
86} // namespace vctr
Definition: ElementwiseMax.h:28
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
The main namespace of the VCTR project.
Definition: Array.h:24
constexpr void assertCommonSize(const A &a, const B &b)
Ensures that both sources have the same size.
Definition: Traits.h:256
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
constexpr auto elementwiseMax(SrcAType &&a, SrcBType &&b)
Computes the element-wise maximum of two sources.
Definition: ElementwiseMax.h:79
Definition: AVXRegister.h:28
The base class to every expression template.
Definition: ExpressionTemplate.h:37
Definition: NeonRegister.h:28
Definition: SSERegister.h:28