VCTR
Loading...
Searching...
No Matches
Divide.h
1/*
2 ==============================================================================
3 DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
5 Copyright 2022- 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{
25
26//==============================================================================
28template <size_t extent, class SrcAType, class SrcBType>
30{
31public:
32 using value_type = std::common_type_t<ValueType<SrcAType>, ValueType<SrcBType>>;
33
34 VCTR_COMMON_BINARY_VEC_VEC_EXPRESSION_MEMBERS (DivideVectors, srcA, srcB)
35
36 VCTR_FORCEDINLINE constexpr value_type operator[] (size_t i) const
37 {
38 return srcA[i] / srcB[i];
39 }
40
41 VCTR_FORCEDINLINE const value_type* evalNextVectorOpInExpressionChain (value_type* dst) const
43 {
44 Expression::Accelerate::div (srcA.evalNextVectorOpInExpressionChain (dst), srcB.evalNextVectorOpInExpressionChain (dst), dst, size());
45 return dst;
46 }
47
48 VCTR_FORCEDINLINE const value_type* evalNextVectorOpInExpressionChain (value_type* dst) const
50 {
51 Expression::IPP::div (srcA.evalNextVectorOpInExpressionChain (dst), srcB.evalNextVectorOpInExpressionChain (dst), dst, size());
52 return dst;
53 }
54
55 //==============================================================================
56 // AVX Implementation
57 VCTR_FORCEDINLINE VCTR_TARGET ("avx") AVXRegister<value_type> getAVX (size_t i) const
58 requires (archX64 && has::getAVX<SrcAType> && has::getAVX<SrcBType> && Expression::CommonElement::isRealFloat)
59 {
60 return Expression::AVX::div (srcA.getAVX (i), srcB.getAVX (i));
61 }
62
63 //==============================================================================
64 // SSE Implementation
65 VCTR_FORCEDINLINE VCTR_TARGET ("sse4.1") SSERegister<value_type> getSSE (size_t i) const
66 requires (archX64 && has::getSSE<SrcAType> && has::getSSE<SrcBType> && Expression::CommonElement::isRealFloat)
67 {
68 return Expression::SSE::div (srcA.getSSE (i), srcB.getSSE (i));
69 }
70};
71
72//==============================================================================
74template <size_t extent, class SrcType>
76{
77public:
78 using value_type = ValueType<SrcType>;
79
80 VCTR_COMMON_BINARY_SINGLE_VEC_EXPRESSION_MEMBERS (DivideSingleByVec, src, single)
81
82 VCTR_FORCEDINLINE constexpr value_type operator[] (size_t i) const
83 {
84 return single / src[i];
85 }
86
87 VCTR_FORCEDINLINE const value_type* evalNextVectorOpInExpressionChain (value_type* dst) const
88 requires is::suitableForIppRealFloatVectorOp<SrcType, value_type> && std::same_as<float, value_type>
89 {
90 Expression::IPP::div (single, src.evalNextVectorOpInExpressionChain (dst), dst, sizeToInt (size()));
91 return dst;
92 }
93
94 //==============================================================================
95 // AVX Implementation
96 VCTR_FORCEDINLINE VCTR_TARGET ("avx") AVXRegister<value_type> getAVX (size_t i) const
97 requires (archX64 && has::getAVX<SrcType> && Expression::allElementTypesSame && Expression::CommonElement::isRealFloat)
98 {
99 return Expression::AVX::div (Expression::AVX::fromSSE (singleAsSSE, singleAsSSE), src.getAVX (i));
100 }
101
102 //==============================================================================
103 // SSE Implementation
104 VCTR_FORCEDINLINE VCTR_TARGET ("sse4.1") SSERegister<value_type> getSSE (size_t i) const
105 requires (archX64 && has::getSSE<SrcType> && Expression::allElementTypesSame && Expression::CommonElement::isRealFloat)
106 {
107 return Expression::SSE::div (singleAsSSE, src.getSSE (i));
108 }
109};
110
111//==============================================================================
113template <size_t extent, class SrcType>
115{
116public:
117 using value_type = ValueType<SrcType>;
118
119 VCTR_COMMON_BINARY_SINGLE_VEC_EXPRESSION_MEMBERS (DivideVecBySingle, src, single)
120
121 VCTR_FORCEDINLINE constexpr value_type operator[] (size_t i) const
122 {
123 return src[i] / single;
124 }
125
126 VCTR_FORCEDINLINE const value_type* evalNextVectorOpInExpressionChain (value_type* dst) const
128 {
129 Expression::Accelerate::div (src.evalNextVectorOpInExpressionChain (dst), single, dst, size());
130 return dst;
131 }
132
133 VCTR_FORCEDINLINE const value_type* evalNextVectorOpInExpressionChain (value_type* dst) const
135 {
136 Expression::IPP::div (src.evalNextVectorOpInExpressionChain (dst), single, dst, size());
137 return dst;
138 }
139
140 //==============================================================================
141 // AVX Implementation
142 VCTR_FORCEDINLINE VCTR_TARGET ("avx") AVXRegister<value_type> getAVX (size_t i) const
143 requires (archX64 && has::getAVX<SrcType> && Expression::allElementTypesSame && Expression::CommonElement::isRealFloat)
144 {
145 return Expression::AVX::div (src.getAVX (i), Expression::AVX::fromSSE (singleAsSSE, singleAsSSE));
146 }
147
148 //==============================================================================
149 // SSE Implementation
150 VCTR_FORCEDINLINE VCTR_TARGET ("sse4.1") SSERegister<value_type> getSSE (size_t i) const
151 requires (archX64 && has::getSSE<SrcType> && Expression::allElementTypesSame && Expression::CommonElement::isRealFloat)
152 {
153 return Expression::SSE::div (src.getSSE (i), singleAsSSE);
154 }
155};
156
157} // namespace vctr::expressions
158
159namespace vctr
160{
161
166template <class SrcAType, class SrcBType>
169constexpr auto operator/ (SrcAType&& a, SrcBType&& b)
170{
171 assertCommonSize (a, b);
172 constexpr auto extent = getCommonExtent<SrcAType, SrcBType>();
173
174 return expressions::DivideVectors<extent, SrcAType, SrcBType> (std::forward<SrcAType> (a), std::forward<SrcBType> (b));
175}
176
181template <class Src>
182requires is::anyVctrOrExpression<Src>
183constexpr auto operator/ (typename std::remove_cvref_t<Src>::value_type single, Src&& vec)
184{
185 return expressions::DivideSingleByVec<extentOf<Src>, Src> (single, std::forward<Src> (vec));
186}
187
192template <class Src>
193requires is::anyVctrOrExpression<Src>
194constexpr auto operator/ (Src&& vec, typename std::remove_cvref_t<Src>::value_type single)
195{
196 return expressions::DivideVecBySingle<extentOf<Src>, Src> (single, std::forward<Src> (vec));
197}
198
199} // namespace vctr
Divides a single value by a vector.
Definition: Divide.h:76
Divides a vector like type by a single value.
Definition: Divide.h:115
Divides two vector like types.
Definition: Divide.h:30
Constrains a type to have a member function getAVX (size_t) const.
Definition: ContainerAndExpressionConcepts.h:78
Constrains a type to have a member function getSSE (size_t) const.
Definition: ContainerAndExpressionConcepts.h:82
Constrains a type to either be an expression template or any derived instance of VctrBase.
Definition: ContainerAndExpressionConcepts.h:212
A combined concept to check if Apple Accelerate is a suitable option for a real valued floating point...
Definition: ContainerAndExpressionConcepts.h:242
A combined concept to check if Apple Accelerate is a suitable option for a real or complex valued flo...
Definition: ContainerAndExpressionConcepts.h:311
A combined concept to check if Intel IPP is a suitable option for a real valued floating point vector...
Definition: ContainerAndExpressionConcepts.h:266
A combined concept to check if Intel IPP is a suitable option for a real or complex valued floating p...
Definition: ContainerAndExpressionConcepts.h:324
A combined concept to check if Intel IPP is a suitable option for a real or complex valued floating p...
Definition: ContainerAndExpressionConcepts.h:278
constexpr auto operator/(SrcAType &&a, SrcBType &&b)
Returns an expression that divides vector or expression a by vector or expression b.
Definition: Divide.h:169
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:253
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
The base class to every expression template.
Definition: ExpressionTemplate.h:37
Definition: SSERegister.h:28