HILA
Loading...
Searching...
No Matches
vector_types.h
1#ifndef VECTOR_TYPES_H
2#define VECTOR_TYPES_H
3
4namespace hila {
5
6/// is_vectorizable_type<T>::value is always false if the target is not vectorizable
7template <typename T, typename A = void>
9 static constexpr bool value = false;
10};
11
12#ifdef VECTORIZED
13/// specialize is_vectorizable_type<T>::value to true if the base_type_struct<T>::type
14/// exists
15// template <typename T>
16// struct is_vectorizable_type<T, typename std::enable_if_t<std::is_arithmetic<
17// typename hila::base_type_struct<T>::type>::value>> {
18// static constexpr bool value = true;
19// };
20
21template <typename T>
22struct is_vectorizable_type<T, typename std::enable_if_t<std::is_same<hila::arithmetic_type<T>, int>::value>> {
23 static constexpr bool value = true;
24};
25template <typename T>
26struct is_vectorizable_type<T, typename std::enable_if_t<std::is_same<hila::arithmetic_type<T>, unsigned int>::value>> {
27 static constexpr bool value = true;
28};
29template <typename T>
30struct is_vectorizable_type<T, typename std::enable_if_t<std::is_same<hila::arithmetic_type<T>, int64_t>::value>> {
31 static constexpr bool value = true;
32};
33template <typename T>
34struct is_vectorizable_type<T, typename std::enable_if_t<std::is_same<hila::arithmetic_type<T>, uint64_t>::value>> {
35 static constexpr bool value = true;
36};
37template <typename T>
38struct is_vectorizable_type<T, typename std::enable_if_t<std::is_same<hila::arithmetic_type<T>, float>::value>> {
39 static constexpr bool value = true;
40};
41template <typename T>
42struct is_vectorizable_type<T, typename std::enable_if_t<std::is_same<hila::arithmetic_type<T>, double>::value>> {
43 static constexpr bool value = true;
44};
45
46
47/// do forward definition here, enables inclusion
48template <int vector_size>
50
51// clang-format off
52/// Utility for selecting a vector type by base type and length
53template <typename T, int vector_len> struct vector_base_type {};
54
55template <> struct vector_base_type<int,4> { using type = Vec4i; };
56template <> struct vector_base_type<double, 4> { using type = Vec4d; };
57template <> struct vector_base_type<double, 8> { using type = Vec8d; };
58template <> struct vector_base_type<float, 8> { using type = Vec8f; };
59template <> struct vector_base_type<float, 16> { using type = Vec16f; };
60template <> struct vector_base_type<int, 8> { using type = Vec8i; };
61template <> struct vector_base_type<unsigned int, 8> { using type = Vec8ui; };
62template <> struct vector_base_type<int, 16> { using type = Vec16i; };
63template <> struct vector_base_type<unsigned int, 16> { using type = Vec16ui; };
64template <> struct vector_base_type<int64_t, 4> { using type = Vec4q; };
65template <> struct vector_base_type<uint64_t, 4> { using type = Vec4uq; };
66template <> struct vector_base_type<int64_t, 8> { using type = Vec8q; };
67template <> struct vector_base_type<uint64_t, 8> { using type = Vec8uq; };
68// clang-format on
69
70// template<>
71// struct vector_base_type<CoordinateVector, 4> {
72// using type = Vec4i;
73// };
74
75// template<>
76// struct vector_base_type<CoordinateVector, 8> {
77// using type = Vec8i;
78// };
79
80#endif // VECTORIZED
81
82/// Construct the vector info for the type.
83/// first, if the type is not vectorizable
84template <typename T, typename A = void>
86 static constexpr bool is_vectorizable = false;
87 using base_type = T;
88 // Find vector length
89 static constexpr int vector_size = 1;
90 // Find the vector type from above
91 using type = void;
92 // Number of elements in the full type
93 static constexpr int elements = 1;
94 // Size of the base type
95 static constexpr int base_type_size = sizeof(base_type);
96};
97
98#ifdef VECTORIZED
99
100/// and specializre the same for vectorizable type
101template <typename T>
102struct vector_info<T, typename std::enable_if_t<hila::is_vectorizable_type<T>::value>> {
103 static constexpr bool is_vectorizable = true;
104 // Get base type first
105 using base_type = hila::arithmetic_type<T>;
106 // Find vector length
107 static constexpr int vector_size = VECTOR_SIZE / sizeof(base_type);
108 // Find the vector type from above
109 using type = typename vector_base_type<base_type, vector_size>::type;
110 // Number of elements in the full type
111 static constexpr int elements = sizeof(T) / sizeof(base_type);
112 // Size of the base type
113 static constexpr int base_type_size = sizeof(base_type);
114};
115
116#endif // VECTORIZED
117
118} // namespace hila
119
120#endif
Implement hila::swap for gauge fields.
Definition array.h:981
is_vectorizable_type<T>::value is always false if the target is not vectorizable
Definition vector_types.h:8