VCTR
Loading...
Searching...
No Matches
SIMDFilter.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
26template <size_t extent, class SrcType>
28{
29public:
30 using value_type = ValueType<SrcType>;
31
32 VCTR_COMMON_UNARY_EXPRESSION_MEMBERS (SSEFilter, src)
33
34 VCTR_FORCEDINLINE constexpr value_type operator[] (size_t i) const
35 {
36 return src[i];
37 }
38
39 //==============================================================================
40 VCTR_FORWARD_PREPARE_SIMD_EVALUATION_UNARY_EXPRESSION_MEMBER_FUNCTIONS
41
42 VCTR_FORCEDINLINE VCTR_TARGET ("sse4.1") SSERegister<value_type> getSSE (size_t i) const
43 requires (archX64 && has::getSSE<SrcType>)
44 {
45 return src.getSSE (i);
46 }
47};
48
49template <size_t extent, class SrcType>
51{
52public:
53 using value_type = ValueType<SrcType>;
54
55 VCTR_COMMON_UNARY_EXPRESSION_MEMBERS (AVXFilter, src)
56
57 VCTR_FORCEDINLINE constexpr value_type operator[] (size_t i) const
58 {
59 return src[i];
60 }
61
62 //==============================================================================
63 VCTR_FORWARD_PREPARE_SIMD_EVALUATION_UNARY_EXPRESSION_MEMBER_FUNCTIONS
64
65 VCTR_FORCEDINLINE VCTR_TARGET ("fma") AVXRegister<value_type> getAVX (size_t i) const
67 {
68 return src.getAVX (i);
69 }
70
71 VCTR_FORCEDINLINE VCTR_TARGET ("avx2") AVXRegister<value_type> getAVX (size_t i) const
73 {
74 return src.getAVX (i);
75 }
76};
77
78template <size_t extent, class SrcType>
80{
81public:
82 using value_type = ValueType<SrcType>;
83
84 VCTR_COMMON_UNARY_EXPRESSION_MEMBERS (NeonFilter, src)
85
86 VCTR_FORCEDINLINE constexpr value_type operator[] (size_t i) const
87 {
88 return src[i];
89 }
90
91 //==============================================================================
92 VCTR_FORWARD_PREPARE_SIMD_EVALUATION_UNARY_EXPRESSION_MEMBER_FUNCTIONS
93
94 NeonRegister<value_type> getNeon (size_t i) const
95 requires (archARM && has::getNeon<SrcType>)
96 {
97 return src.getNeon (i);
98 }
99};
100
101template <size_t extent, class SrcType>
103{
104public:
105 using value_type = ValueType<SrcType>;
106
107 VCTR_COMMON_UNARY_EXPRESSION_MEMBERS (AnySIMDFilter, src)
108
109 VCTR_FORCEDINLINE constexpr value_type operator[] (size_t i) const
110 {
111 return src[i];
112 }
113
114 //==============================================================================
115 VCTR_FORWARD_PREPARE_SIMD_EVALUATION_UNARY_EXPRESSION_MEMBER_FUNCTIONS
116
117 VCTR_FORCEDINLINE VCTR_TARGET ("sse4.1") SSERegister<value_type> getSSE (size_t i) const
118 requires (archX64 && has::getSSE<SrcType>)
119 {
120 return src.getSSE (i);
121 }
122
123 VCTR_FORCEDINLINE VCTR_TARGET ("fma") AVXRegister<value_type> getAVX (size_t i) const
125 {
126 return src.getAVX (i);
127 }
128
129 VCTR_FORCEDINLINE VCTR_TARGET ("avx2") AVXRegister<value_type> getAVX (size_t i) const
131 {
132 return src.getAVX (i);
133 }
134
135 NeonRegister<value_type> getNeon (size_t i) const
136 requires (archARM && has::getNeon<SrcType>)
137 {
138 return src.getNeon (i);
139 }
140};
141
142template <size_t extent, class SrcType>
144{
145public:
146 using value_type = ValueType<SrcType>;
147
148 VCTR_COMMON_UNARY_EXPRESSION_MEMBERS (AssertSIMDFilter, src)
149
150 VCTR_FORCEDINLINE constexpr value_type operator[] (size_t i) const
151 {
152 VCTR_ASSERT (false);
153 return src[i];
154 }
155
156 //==============================================================================
157 auto* data() const
158 requires has::data<SrcType>
159 {
160 return src.data();
161 }
162
163 VCTR_FORCEDINLINE const value_type* evalNextVectorOpInExpressionChain (value_type* dst) const
165 {
166 VCTR_ASSERT (false);
167 return src.evalNextVectorOpInExpressionChain (dst);
168 }
169
170 //==============================================================================
171 VCTR_FORWARD_PREPARE_SIMD_EVALUATION_UNARY_EXPRESSION_MEMBER_FUNCTIONS
172
173 VCTR_FORCEDINLINE VCTR_TARGET ("sse4.1") SSERegister<value_type> getSSE (size_t i) const
174 requires (archX64 && has::getSSE<SrcType>)
175 {
176 return src.getSSE (i);
177 }
178
179 VCTR_FORCEDINLINE VCTR_TARGET ("fma") AVXRegister<value_type> getAVX (size_t i) const
181 {
182 return src.getAVX (i);
183 }
184
185 VCTR_FORCEDINLINE VCTR_TARGET ("avx2") AVXRegister<value_type> getAVX (size_t i) const
187 {
188 return src.getAVX (i);
189 }
190
191 NeonRegister<value_type> getNeon (size_t i) const
192 requires (archARM && has::getNeon<SrcType>)
193 {
194 return src.getNeon (i);
195 }
196};
197
198} // namespace vctr::expressions
199
200namespace vctr
201{
202
210
218
226
227#if VCTR_ARM
228constexpr inline ExpressionChainBuilder<expressions::NeonFilter> useNeonOrAVX;
229constexpr inline ExpressionChainBuilder<expressions::NeonFilter> useNeonOrSSE;
230#else
231constexpr inline ExpressionChainBuilder<expressions::AVXFilter> useNeonOrAVX;
232constexpr inline ExpressionChainBuilder<expressions::SSEFilter> useNeonOrSSE;
233#endif
234
243
251} // namespace vctr
Definition: SIMDFilter.h:51
Definition: SIMDFilter.h:103
Definition: SIMDFilter.h:144
Definition: SIMDFilter.h:80
Definition: SIMDFilter.h:28
Constrains a type to have a member function data() const.
Definition: ContainerAndExpressionConcepts.h:136
Constrains a type to have a member function evalNextVectorOpInExpressionChain (value_type*) const.
Definition: ContainerAndExpressionConcepts.h:112
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 represent a real valued floating point number.
Definition: NumericTypeConcepts.h:83
constexpr ExpressionChainBuilder< expressions::SSEFilter > useSSE
This filter expression ensures that only SSE based accelerated evaluation of the previous expression ...
Definition: SIMDFilter.h:209
constexpr ExpressionChainBuilder< expressions::AVXFilter > useAVX
This filter expression ensures that only AVX based accelerated evaluation of the previous expression ...
Definition: SIMDFilter.h:217
constexpr ExpressionChainBuilder< expressions::NeonFilter > useNeon
This filter expression ensures that only Neon based accelerated evaluation of the previous expression...
Definition: SIMDFilter.h:225
constexpr ExpressionChainBuilder< expressions::AnySIMDFilter > useSIMD
This filter expression ensures that only SIMD based accelerated evaluation of the previous expression...
Definition: SIMDFilter.h:242
constexpr ExpressionChainBuilder< expressions::AssertSIMDFilter > assertSIMD
This filter inserts an assertion that will be hit in case that an expression is evaluated with anythi...
Definition: SIMDFilter.h:250
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
Definition: AVXRegister.h:28
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