Grid 0.7.0
Grid_generic_types.h
Go to the documentation of this file.
1/*************************************************************************************
2
3 Grid physics library, www.github.com/paboyle/Grid
4
5 Source file: ./lib/simd/Grid_generic_types.h
6
7 Copyright (C) 2017
8
9Author: Antonin Portelli <antonin.portelli@me.com>
10 Andrew Lawson <andrew.lawson1991@gmail.com>
11
12 This program is free software; you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by
14 the Free Software Foundation; either version 2 of the License, or
15 (at your option) any later version.
16
17 This program is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
21
22 You should have received a copy of the GNU General Public License along
23 with this program; if not, write to the Free Software Foundation, Inc.,
24 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25
26 See the full license in the file "LICENSE" in the top level distribution directory
27*************************************************************************************/
28/* END LEGAL */
29
30static_assert(GEN_SIMD_WIDTH % 16u == 0, "SIMD vector size is not an integer multiple of 16 bytes");
31
32#undef VECTOR_LOOPS
33
34// playing with compiler pragmas
35
36#ifdef VECTOR_LOOPS
37#ifdef __clang__
38#define VECTOR_FOR(i, w, inc) \
39 _Pragma("clang loop unroll(full) vectorize(enable) interleave(enable) vectorize_width(w)") \
40 for (unsigned int i = 0; i < w; i += inc)
41#elif defined __INTEL_COMPILER
42#define VECTOR_FOR(i, w, inc) \
43 _Pragma("simd vectorlength(w*8)") \
44 for (unsigned int i = 0; i < w; i += inc)
45#else
46#define VECTOR_FOR(i, w, inc) \
47 for (unsigned int i = 0; i < w; i += inc)
48#endif
49#else
50#define VECTOR_FOR(i, w, inc) \
51 for (unsigned int i = 0; i < w; i += inc)
52#endif
53
55NAMESPACE_BEGIN(Optimization);
56
57#ifdef GENERIC_SCALAR
58
59// type traits giving the number of elements for each vector type
60template <typename T> struct W;
61template <> struct W<double> {
62 constexpr static unsigned int c = 1;
63 constexpr static unsigned int r = 2;
64};
65template <> struct W<float> {
66 constexpr static unsigned int c = 1;
67 constexpr static unsigned int r = 2;
68};
69template <> struct W<Integer> {
70 constexpr static unsigned int r = 1;
71};
72template <> struct W<uint16_t> {
73 constexpr static unsigned int c = 1;
74 constexpr static unsigned int r = 2;
75};
76// SIMD vector types
77template <typename T>
78struct vec {
79 T v[W<T>::r];
80};
81#else
82// type traits giving the number of elements for each vector type
83template <typename T> struct W;
84template <> struct W<double> {
85 constexpr static unsigned int c = GEN_SIMD_WIDTH/16u;
86 constexpr static unsigned int r = GEN_SIMD_WIDTH/8u;
87};
88template <> struct W<float> {
89 constexpr static unsigned int c = GEN_SIMD_WIDTH/8u;
90 constexpr static unsigned int r = GEN_SIMD_WIDTH/4u;
91};
92template <> struct W<Integer> {
93 constexpr static unsigned int r = GEN_SIMD_WIDTH/4u;
94};
95template <> struct W<uint16_t> {
96 constexpr static unsigned int c = GEN_SIMD_WIDTH/4u;
97 constexpr static unsigned int r = GEN_SIMD_WIDTH/2u;
98};
99// SIMD vector types
100template <typename T>
101struct vec {
102 alignas(GEN_SIMD_WIDTH) T v[W<T>::r];
103};
104#endif
105
108typedef vec<uint16_t> vech; // half precision comms
110
111NAMESPACE_END(Optimization);
#define GEN_SIMD_WIDTH
Definition Config.h:56
vec< double > vecd
vec< Integer > veci
vec< float > vecf
vec< uint16_t > vech
#define NAMESPACE_BEGIN(A)
Definition Namespace.h:35
#define NAMESPACE_END(A)
Definition Namespace.h:36
uint32_t Integer
Definition Simd.h:58
T v[W< T >::r]