TrioCFD 1.9.8
TrioCFD documentation
Loading...
Searching...
No Matches
Simd_VectorArray_template.h
1/****************************************************************************
2* Copyright (c) 2022, CEA
3* All rights reserved.
4*
5* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
6* 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
7* 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
8* 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
9*
10* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
11* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
12* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
13*
14*****************************************************************************/
15
16#ifndef Simd_VectorArray_template_included
17#define Simd_VectorArray_template_included
18
19#include <Simd_template.h>
20#include <FixedVector.h>
21
22// Simd_VectorArray_template stores N vectors of size VectorSize arranged for Simd operation (one simd load or store accesses one
23// particular component of the vector for n consecutive vectors).
24// It is a fixed size storage that should be used for efficient processing of local data (that fit in the L1 cache)
25template<typename _TYPE_, int N, int VectorSize>
27{
28public:
29 _TYPE_& operator()(int vector_index, int component)
30 {
31 assert(vector_index >= 0 && vector_index < N && component >= 0 && component < VectorSize);
32 return data_[component][vector_index];
33 }
34
35 const _TYPE_& operator()(int vector_index, int component) const
36 {
37 assert(vector_index >= 0 && vector_index < N && component >= 0 && component < VectorSize);
38 return data_[component][vector_index];
39 }
40
41 Simd_template<_TYPE_> SimdGet(int vector_index, int component) const
42 {
43 assert(vector_index >= 0 && vector_index < N && component >= 0 && component < VectorSize);
44 return SimdGet(data_[component] + vector_index);
45 }
46
47 void SimdPut(int vector_index, int component, const Simd_template<_TYPE_>& x)
48 {
49 assert(vector_index >= 0 && vector_index < N && component >= 0 && component < VectorSize);
50 SimdPut(data_[component] + vector_index, x);
51 }
52
54 {
55 assert(i >= 0 && i < N);
57 for (int j = 0; j < VectorSize; j++) v[j] = ::SimdGet(data_[j] + i);
58 return v;
59 }
60
61protected:
62 // Fortran type storage to allow vectorized operation on n consecutive vectors:
63 _TYPE_ data_[VectorSize][N];
64};
65
66template <int N, int VectorSize> using Simd_intVectorArray = Simd_VectorArray_template<int,N,VectorSize>;
67template <int N, int VectorSize> using Simd_floatVectorArray = Simd_VectorArray_template<float,N,VectorSize>;
68template <int N, int VectorSize> using Simd_doubleVectorArray = Simd_VectorArray_template<double,N,VectorSize>;
69
70#endif /* Simd_VectorArray_template_included */
Simd_template< _TYPE_ > SimdGet(int vector_index, int component) const
_TYPE_ & operator()(int vector_index, int component)
const _TYPE_ & operator()(int vector_index, int component) const
void SimdPut(int vector_index, int component, const Simd_template< _TYPE_ > &x)
FixedVector< Simd_template< _TYPE_ >, VectorSize > SimdGetVector(int i)
This class provides a generic access to simd operations on x86, x86 AMD and ARM architectures.