1 //=================================================================================================
2 /*!
3 //  \file blaze/math/expressions/VecNoSIMDExpr.h
4 //  \brief Header file for the VecNoSIMDExpr base class
5 //
6 //  Copyright (C) 2012-2020 Klaus Iglberger - All Rights Reserved
7 //
8 //  This file is part of the Blaze library. You can redistribute it and/or modify it under
9 //  the terms of the New (Revised) BSD License. Redistribution and use in source and binary
10 //  forms, with or without modification, are permitted provided that the following conditions
11 //  are met:
12 //
13 //  1. Redistributions of source code must retain the above copyright notice, this list of
14 //     conditions and the following disclaimer.
15 //  2. Redistributions in binary form must reproduce the above copyright notice, this list
16 //     of conditions and the following disclaimer in the documentation and/or other materials
17 //     provided with the distribution.
18 //  3. Neither the names of the Blaze development group nor the names of its contributors
19 //     may be used to endorse or promote products derived from this software without specific
20 //     prior written permission.
21 //
22 //  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
23 //  EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24 //  OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
25 //  SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 //  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
27 //  TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
28 //  BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 //  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
30 //  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
31 //  DAMAGE.
32 */
33 //=================================================================================================
34 
35 #ifndef _BLAZE_MATH_EXPRESSIONS_VECNOSIMDEXPR_H_
36 #define _BLAZE_MATH_EXPRESSIONS_VECNOSIMDEXPR_H_
37 
38 
39 //*************************************************************************************************
40 // Includes
41 //*************************************************************************************************
42 
43 #include <blaze/math/expressions/CrossExpr.h>
44 #include <blaze/math/expressions/MatReduceExpr.h>
45 #include <blaze/math/expressions/MatVecMultExpr.h>
46 #include <blaze/math/expressions/NoSIMDExpr.h>
47 #include <blaze/math/expressions/TVecMatMultExpr.h>
48 #include <blaze/math/expressions/VecEvalExpr.h>
49 #include <blaze/math/expressions/VecMapExpr.h>
50 #include <blaze/math/expressions/VecNoAliasExpr.h>
51 #include <blaze/math/expressions/VecRepeatExpr.h>
52 #include <blaze/math/expressions/VecScalarMultExpr.h>
53 #include <blaze/math/expressions/VecScalarDivExpr.h>
54 #include <blaze/math/expressions/VecSerialExpr.h>
55 #include <blaze/math/expressions/VecTransExpr.h>
56 #include <blaze/math/expressions/VecVecAddExpr.h>
57 #include <blaze/math/expressions/VecVecDivExpr.h>
58 #include <blaze/math/expressions/VecVecKronExpr.h>
59 #include <blaze/math/expressions/VecVecMapExpr.h>
60 #include <blaze/math/expressions/VecVecMultExpr.h>
61 #include <blaze/math/expressions/VecVecSubExpr.h>
62 #include <blaze/math/ReductionFlag.h>
63 #include <blaze/util/FunctionTrace.h>
64 
65 
66 namespace blaze {
67 
68 //=================================================================================================
69 //
70 //  CLASS DEFINITION
71 //
72 //=================================================================================================
73 
74 //*************************************************************************************************
75 /*!\brief Base class for all vector no-SIMD expression templates.
76 // \ingroup math
77 //
78 // The VecNoSIMDExpr class serves as a tag for all expression templates that implement a vector
79 // no-SIMD operation. All classes, that represent a vector no-SIMD operation and that are used
80 // within the expression template environment of the Blaze library have to derive publicly from
81 // this class in order to qualify as vector no-SIMD expression template. Only in case a class is
82 // derived publicly from the VecNoSIMDExpr base class, the IsVecNoSIMDExpr type trait recognizes
83 // the class as valid vector no-SIMD expression template.
84 */
85 template< typename VT >  // Vector base type of the expression
86 struct VecNoSIMDExpr
87    : public NoSIMDExpr<VT>
88 {};
89 //*************************************************************************************************
90 
91 
92 
93 
94 //=================================================================================================
95 //
96 //  GLOBAL RESTRUCTURING FUNCTIONS
97 //
98 //=================================================================================================
99 
100 //*************************************************************************************************
101 /*! \cond BLAZE_INTERNAL */
102 /*!\brief Disable the SIMD evaluation of the given vector/vector addition.
103 // \ingroup math
104 //
105 // \param vector The constant vector/vector addition.
106 // \return The SIMD-disabled addition.
107 //
108 // This function returns an expression representing the SIMD-disabled vector/vector addition.
109 */
110 template< typename VT >  // Vector base type of the expression
decltype(auto)111 inline decltype(auto) nosimd( const VecVecAddExpr<VT>& vector )
112 {
113    BLAZE_FUNCTION_TRACE;
114 
115    return nosimd( (*vector).leftOperand() ) + nosimd( (*vector).rightOperand() );
116 }
117 /*! \endcond */
118 //*************************************************************************************************
119 
120 
121 //*************************************************************************************************
122 /*! \cond BLAZE_INTERNAL */
123 /*!\brief Disable the SIMD evaluation of the given vector/vector subtraction.
124 // \ingroup math
125 //
126 // \param vector The constant vector/vector subtraction.
127 // \return The SIMD-disabled subtraction.
128 //
129 // This function returns an expression representing the SIMD-disabled vector/vector subtraction.
130 */
131 template< typename VT >  // Vector base type of the expression
decltype(auto)132 inline decltype(auto) nosimd( const VecVecSubExpr<VT>& vector )
133 {
134    BLAZE_FUNCTION_TRACE;
135 
136    return nosimd( (*vector).leftOperand() ) - nosimd( (*vector).rightOperand() );
137 }
138 /*! \endcond */
139 //*************************************************************************************************
140 
141 
142 //*************************************************************************************************
143 /*! \cond BLAZE_INTERNAL */
144 /*!\brief Disable the SIMD evaluation of the given vector/vector multiplication.
145 // \ingroup math
146 //
147 // \param vector The constant vector/vector multiplication.
148 // \return The SIMD-disabled multiplication.
149 //
150 // This function returns an expression representing the SIMD-disabled vector/vector multiplication.
151 */
152 template< typename VT >  // Vector base type of the expression
decltype(auto)153 inline decltype(auto) nosimd( const VecVecMultExpr<VT>& vector )
154 {
155    BLAZE_FUNCTION_TRACE;
156 
157    return nosimd( (*vector).leftOperand() ) * nosimd( (*vector).rightOperand() );
158 }
159 /*! \endcond */
160 //*************************************************************************************************
161 
162 
163 //*************************************************************************************************
164 /*! \cond BLAZE_INTERNAL */
165 /*!\brief Disable the SIMD evaluation of the given vector/vector Kronecker product.
166 // \ingroup math
167 //
168 // \param vector The constant vector/vector Kronecker product.
169 // \return The SIMD-disabled Kronecker product.
170 //
171 // This function returns an expression representing the SIMD-disabled vector/vector Kronecker
172 // product.
173 */
174 template< typename VT >  // Vector base type of the expression
decltype(auto)175 inline decltype(auto) nosimd( const VecVecKronExpr<VT>& vector )
176 {
177    BLAZE_FUNCTION_TRACE;
178 
179    return kron( nosimd( (*vector).leftOperand() ), nosimd( (*vector).rightOperand() ) );
180 }
181 /*! \endcond */
182 //*************************************************************************************************
183 
184 
185 //*************************************************************************************************
186 /*! \cond BLAZE_INTERNAL */
187 /*!\brief Disable the SIMD evaluation of the given vector/vector division.
188 // \ingroup math
189 //
190 // \param vector The constant vector/vector division.
191 // \return The SIMD-disabled division.
192 //
193 // This function returns an expression representing the SIMD-disabled vector/vector division.
194 */
195 template< typename VT >  // Vector base type of the expression
decltype(auto)196 inline decltype(auto) nosimd( const VecVecDivExpr<VT>& vector )
197 {
198    BLAZE_FUNCTION_TRACE;
199 
200    return nosimd( (*vector).leftOperand() ) / nosimd( (*vector).rightOperand() );
201 }
202 /*! \endcond */
203 //*************************************************************************************************
204 
205 
206 //*************************************************************************************************
207 /*! \cond BLAZE_INTERNAL */
208 /*!\brief Disable the SIMD evaluation of the given vector/vector cross product.
209 // \ingroup math
210 //
211 // \param vector The constant vector/vector cross product.
212 // \return The SIMD-disabled cross product.
213 //
214 // This function returns an expression representing the SIMD-disabled vector/vector cross product.
215 */
216 template< typename VT >  // Vector base type of the expression
decltype(auto)217 inline decltype(auto) nosimd( const CrossExpr<VT>& vector )
218 {
219    BLAZE_FUNCTION_TRACE;
220 
221    return nosimd( (*vector).leftOperand() ) % nosimd( (*vector).rightOperand() );
222 }
223 /*! \endcond */
224 //*************************************************************************************************
225 
226 
227 //*************************************************************************************************
228 /*! \cond BLAZE_INTERNAL */
229 /*!\brief Disable the SIMD evaluation of the given vector/scalar multiplication.
230 // \ingroup math
231 //
232 // \param vector The constant vector/scalar multiplication.
233 // \return The SIMD-disabled multiplication.
234 //
235 // This function returns an expression representing the SIMD-disabled vector/scalar multiplication.
236 */
237 template< typename VT >  // Vector base type of the expression
decltype(auto)238 inline decltype(auto) nosimd( const VecScalarMultExpr<VT>& vector )
239 {
240    BLAZE_FUNCTION_TRACE;
241 
242    return nosimd( (*vector).leftOperand() ) * (*vector).rightOperand();
243 }
244 /*! \endcond */
245 //*************************************************************************************************
246 
247 
248 //*************************************************************************************************
249 /*! \cond BLAZE_INTERNAL */
250 /*!\brief Disable the SIMD evaluation of the given vector/scalar division.
251 // \ingroup math
252 //
253 // \param vector The constant vector/scalar division.
254 // \return The SIMD-disabled division.
255 //
256 // This function returns an expression representing the SIMD-disabled vector/scalar division.
257 */
258 template< typename VT >  // Vector base type of the expression
decltype(auto)259 inline decltype(auto) nosimd( const VecScalarDivExpr<VT>& vector )
260 {
261    BLAZE_FUNCTION_TRACE;
262 
263    return nosimd( (*vector).leftOperand() ) / (*vector).rightOperand();
264 }
265 /*! \endcond */
266 //*************************************************************************************************
267 
268 
269 //*************************************************************************************************
270 /*! \cond BLAZE_INTERNAL */
271 /*!\brief Disable the SIMD evaluation of the given unary vector map operation.
272 // \ingroup math
273 //
274 // \param vector The constant unary vector map operation.
275 // \return The SIMD-disabled unary map operation.
276 //
277 // This function returns an expression representing the SIMD-disabled unary vector map operation.
278 */
279 template< typename VT >  // Vector base type of the expression
decltype(auto)280 inline decltype(auto) nosimd( const VecMapExpr<VT>& vector )
281 {
282    BLAZE_FUNCTION_TRACE;
283 
284    return map( nosimd( (*vector).operand() ), (*vector).operation() );
285 }
286 /*! \endcond */
287 //*************************************************************************************************
288 
289 
290 //*************************************************************************************************
291 /*! \cond BLAZE_INTERNAL */
292 /*!\brief Disable the SIMD evaluation of the given binary vector map operation.
293 // \ingroup math
294 //
295 // \param vector The constant binary vector map operation.
296 // \return The SIMD-disabled binary map operation.
297 //
298 // This function returns an expression representing the SIMD-disabled binary vector map operation.
299 */
300 template< typename VT >  // Vector base type of the expression
decltype(auto)301 inline decltype(auto) nosimd( const VecVecMapExpr<VT>& vector )
302 {
303    BLAZE_FUNCTION_TRACE;
304 
305    return map( nosimd( (*vector).leftOperand() ), nosimd( (*vector).rightOperand() ),
306                (*vector).operation() );
307 }
308 /*! \endcond */
309 //*************************************************************************************************
310 
311 
312 //*************************************************************************************************
313 /*! \cond BLAZE_INTERNAL */
314 /*!\brief Disable the SIMD evaluation of the given vector evaluation operation.
315 // \ingroup math
316 //
317 // \param vector The constant vector evaluation operation.
318 // \return The SIMD-disabled evaluation operation.
319 //
320 // This function returns an expression representing the SIMD-disabled vector evaluation operation.
321 */
322 template< typename VT >  // Vector base type of the expression
decltype(auto)323 inline decltype(auto) nosimd( const VecEvalExpr<VT>& vector )
324 {
325    BLAZE_FUNCTION_TRACE;
326 
327    return eval( nosimd( (*vector).operand() ) );
328 }
329 /*! \endcond */
330 //*************************************************************************************************
331 
332 
333 //*************************************************************************************************
334 /*! \cond BLAZE_INTERNAL */
335 /*!\brief Disable the SIMD evaluation of the given vector serialization operation.
336 // \ingroup math
337 //
338 // \param vector The constant vector serialization operation.
339 // \return The SIMD-disabled serialization operation.
340 //
341 // This function returns an expression representing the SIMD-disabled vector serialization
342 // operation.
343 */
344 template< typename VT >  // Vector base type of the expression
decltype(auto)345 inline decltype(auto) nosimd( const VecSerialExpr<VT>& vector )
346 {
347    BLAZE_FUNCTION_TRACE;
348 
349    return serial( nosimd( (*vector).operand() ) );
350 }
351 /*! \endcond */
352 //*************************************************************************************************
353 
354 
355 //*************************************************************************************************
356 /*! \cond BLAZE_INTERNAL */
357 /*!\brief Disable the SIMD evaluation of the given vector no-alias operation.
358 // \ingroup math
359 //
360 // \param vector The constant vector no-alias operation.
361 // \return The SIMD-disabled no-alias operation.
362 //
363 // This function returns an expression representing the SIMD-disabled vector no-alias operation.
364 */
365 template< typename VT >  // Vector base type of the expression
decltype(auto)366 inline decltype(auto) nosimd( const VecNoAliasExpr<VT>& vector )
367 {
368    BLAZE_FUNCTION_TRACE;
369 
370    return noalias( nosimd( (*vector).operand() ) );
371 }
372 /*! \endcond */
373 //*************************************************************************************************
374 
375 
376 //*************************************************************************************************
377 /*! \cond BLAZE_INTERNAL */
378 /*!\brief Disable the SIMD evaluation of the given vector no-SIMD operation.
379 // \ingroup math
380 //
381 // \param vector The constant vector no-SIMD operation.
382 // \return The SIMD-disabled no-SIMD operation.
383 //
384 // This function returns an expression representing the SIMD-disabled vector no-SIMD operation.
385 */
386 template< typename VT >  // Vector base type of the expression
decltype(auto)387 inline decltype(auto) nosimd( const VecNoSIMDExpr<VT>& vector )
388 {
389    return *vector;
390 }
391 /*! \endcond */
392 //*************************************************************************************************
393 
394 
395 //*************************************************************************************************
396 /*! \cond BLAZE_INTERNAL */
397 /*!\brief Disable the SIMD evaluation of the given vector transpose operation.
398 // \ingroup math
399 //
400 // \param vector The constant vector transpose operation.
401 // \return The SIMD-disabled transpose operation.
402 //
403 // This function returns an expression representing the SIMD-disabled vector transpose
404 // operation.
405 */
406 template< typename VT >  // Vector base type of the expression
decltype(auto)407 inline decltype(auto) nosimd( const VecTransExpr<VT>& vector )
408 {
409    BLAZE_FUNCTION_TRACE;
410 
411    return trans( nosimd( (*vector).operand() ) );
412 }
413 /*! \endcond */
414 //*************************************************************************************************
415 
416 
417 //*************************************************************************************************
418 /*! \cond BLAZE_INTERNAL */
419 /*!\brief Disable the SIMD evaluation of the given matrix/vector multiplication.
420 // \ingroup math
421 //
422 // \param vector The constant matrix/vector multiplication.
423 // \return The SIMD-disabled multiplication.
424 //
425 // This function returns an expression representing the SIMD-disabled matrix/vector
426 // multiplication.
427 */
428 template< typename VT >  // Vector base type of the expression
decltype(auto)429 inline decltype(auto) nosimd( const MatVecMultExpr<VT>& vector )
430 {
431    BLAZE_FUNCTION_TRACE;
432 
433    return nosimd( (*vector).leftOperand() ) * nosimd( (*vector).rightOperand() );
434 }
435 /*! \endcond */
436 //*************************************************************************************************
437 
438 
439 //*************************************************************************************************
440 /*! \cond BLAZE_INTERNAL */
441 /*!\brief Disable the SIMD evaluation of the given vector/matrix multiplication.
442 // \ingroup math
443 //
444 // \param vector The constant vector/matrix multiplication.
445 // \return The SIMD-disabled multiplication.
446 //
447 // This function returns an expression representing the SIMD-disabled vector/matrix
448 // multiplication.
449 */
450 template< typename VT >  // Vector base type of the expression
decltype(auto)451 inline decltype(auto) nosimd( const TVecMatMultExpr<VT>& vector )
452 {
453    BLAZE_FUNCTION_TRACE;
454 
455    return nosimd( (*vector).leftOperand() ) * nosimd( (*vector).rightOperand() );
456 }
457 /*! \endcond */
458 //*************************************************************************************************
459 
460 
461 //*************************************************************************************************
462 /*! \cond BLAZE_INTERNAL */
463 /*!\brief Disable the SIMD evaluation of the given matrix reduction operation.
464 // \ingroup math
465 //
466 // \param vector The constant matrix reduction operation.
467 // \return The SIMD-disabled reduction operation.
468 //
469 // This function returns an expression representing the SIMD-disabled matrix reduction
470 // operation.
471 */
472 template< typename VT         // Vector base type of the expression
473         , ReductionFlag RF >  // Reduction flag
decltype(auto)474 inline decltype(auto) nosimd( const MatReduceExpr<VT,RF>& vector )
475 {
476    BLAZE_FUNCTION_TRACE;
477 
478    return reduce<RF>( nosimd( (*vector).operand() ), (*vector).operation() );
479 }
480 /*! \endcond */
481 //*************************************************************************************************
482 
483 
484 //*************************************************************************************************
485 /*! \cond BLAZE_INTERNAL */
486 /*!\brief Disable the SIMD evaluation of the given vector repeat operation.
487 // ingroup math
488 //
489 // \param vector The constant vector repeat operation.
490 // \return The SIMD-disabled repeat operation.
491 //
492 // This function returns an expression representing the SIMD-disabled vector repeat operation.
493 */
494 template< typename VT  // Vector base type of the expression
495         , size_t R0 >  // Compile time repetitions
decltype(auto)496 inline decltype(auto) nosimd( const VecRepeatExpr<VT,R0>& vector )
497 {
498    BLAZE_FUNCTION_TRACE;
499 
500    return repeat<R0>( nosimd( (*vector).operand() ) );
501 }
502 /*! \endcond */
503 //*************************************************************************************************
504 
505 
506 //*************************************************************************************************
507 /*! \cond BLAZE_INTERNAL */
508 /*!\brief Disable the SIMD evaluation of the given vector repeat operation.
509 // ingroup math
510 //
511 // \param vector The constant vector repeat operation.
512 // \return The SIMD-disabled repeat operation.
513 //
514 // This function returns an expression representing the SIMD-disabled vector repeat operation.
515 */
516 template< typename VT >  // Vector base type of the expression
decltype(auto)517 inline decltype(auto) nosimd( const VecRepeatExpr<VT>& vector )
518 {
519    BLAZE_FUNCTION_TRACE;
520 
521    return repeat( nosimd( (*vector).operand() ), (*vector).template repetitions<0UL>() );
522 }
523 /*! \endcond */
524 //*************************************************************************************************
525 
526 } // namespace blaze
527 
528 #endif
529