Nektar++
Loading...
Searching...
No Matches
library
LibUtilities
SimdLib
traits.hpp
Go to the documentation of this file.
1
///////////////////////////////////////////////////////////////////////////////
2
//
3
// File: traits.hpp
4
//
5
// For more information, please see: http://www.nektar.info
6
//
7
// The MIT License
8
//
9
// Copyright (c) 2006 Division of Applied Mathematics, Brown University (USA),
10
// Department of Aeronautics, Imperial College London (UK), and Scientific
11
// Computing and Imaging Institute, University of Utah (USA).
12
//
13
// Permission is hereby granted, free of charge, to any person obtaining a
14
// copy of this software and associated documentation files (the "Software"),
15
// to deal in the Software without restriction, including without limitation
16
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
17
// and/or sell copies of the Software, and to permit persons to whom the
18
// Software is furnished to do so, subject to the following conditions:
19
//
20
// The above copyright notice and this permission notice shall be included
21
// in all copies or substantial portions of the Software.
22
//
23
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
24
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
26
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
29
// DEALINGS IN THE SOFTWARE.
30
//
31
// Description: Vector type traits and tags.
32
//
33
///////////////////////////////////////////////////////////////////////////////
34
35
#ifndef NEKTAR_LIB_LIBUTILITES_SIMDLIB_TRAITS_H
36
#define NEKTAR_LIB_LIBUTILITES_SIMDLIB_TRAITS_H
37
38
#include <type_traits>
39
40
namespace
tinysimd
41
{
42
43
// Load tags
44
static
constexpr
struct
is_aligned_t
45
{
46
}
is_aligned
{};
47
static
constexpr
struct
is_not_aligned_t
48
{
49
}
is_not_aligned
{};
50
static
constexpr
struct
is_not_reused_t
51
{
52
}
is_not_reused
{};
// streaming, skip cache
53
54
// Check load tags
55
template
<
class
T>
56
struct
is_load_tag
57
: std::integral_constant<
58
bool,
59
std::is_same_v<is_aligned_t, typename std::remove_cv<T>::type> ||
60
std::is_same_v<is_not_aligned_t,
61
typename std::remove_cv<T>::type> ||
62
std::is_same_v<is_not_reused_t, typename std::remove_cv<T>::type>>
63
{
64
};
65
66
template
<
class
T>
67
struct
is_streaming
68
: std::integral_constant<
69
bool,
70
std::is_same_v<is_not_reused_t, typename std::remove_cv<T>::type>>
71
{
72
};
73
74
template
<
class
T>
75
struct
is_requiring_alignment
76
: std::integral_constant<
77
bool,
78
std::is_same_v<is_aligned_t, typename std::remove_cv<T>::type> ||
79
is_streaming<T>::value>
80
{
81
};
82
83
// Helper c++17 style
84
template
<
class
T>
inline
constexpr
bool
is_load_tag_v
=
is_load_tag<T>::value
;
85
template
<
class
T>
86
inline
constexpr
bool
is_streaming_v
=
is_streaming<T>::value
;
87
template
<
class
T>
88
inline
constexpr
bool
is_requiring_alignment_v
=
89
is_requiring_alignment<T>::value
;
90
91
namespace
details
92
{
93
// has width type primary template
94
template
<
class
T,
class
U =
unsigned
int
>
struct
has_width
: std::false_type
95
{
96
};
97
// Specialization for U = unsigned int
98
template
<
class
T>
99
struct
has_width
<T, decltype((void)T::width, 0u)> : std::true_type
100
{
101
};
102
103
// has alignment type primary template
104
template
<
class
T,
class
U =
unsigned
int
>
105
struct
has_alignment
: std::false_type
106
{
107
};
108
// Specialization for U = unsigned int
109
template
<
class
T>
110
struct
has_alignment
<T, decltype((void)T::alignment, 0u)> : std::true_type
111
{
112
};
113
114
// Patch for missing std::void_t in pre C++17 compilers
115
template
<
class
... Ts>
struct
make_void
116
{
117
typedef
void
type
;
118
};
119
template
<
class
... Ts>
using
void_t
=
typename
make_void
<Ts...>::type;
120
121
// Generic template handles types that have no nested ::scalarType member:
122
template
<
class
,
class
=
void
_t<>>
struct
has_scalarType
: std::false_type
123
{
124
};
125
// Specialization recognizes types that do have a nested ::scalarType member:
126
template
<
class
T>
127
struct
has_scalarType
<T,
void_t
<typename T::scalarType>> : std::true_type
128
{
129
};
130
}
// namespace details
131
132
// If it quacks...
133
template
<
class
T>
134
struct
is_vector
135
: std::integral_constant<bool, details::has_alignment<T>::value &&
136
details::has_width<T>::value &&
137
details::has_scalarType<T>::value>
138
{
139
};
140
141
// Helper c++17 style
142
template
<
class
T>
inline
constexpr
bool
is_vector_v
=
is_vector<T>::value
;
143
144
// Generic template handles cases that are not vector type
145
template
<
class
T,
class
=
void
>
146
struct
is_vector_floating_point
: std::false_type
147
{
148
};
149
150
// Specialized template handles cases that are vector types
151
template
<
class
T>
152
struct
is_vector_floating_point
<T,
153
typename
std
::enable_if<is_vector_v<T>>::type>
154
: std::integral_constant<bool,
155
std::is_floating_point_v<typename T::scalarType>>
156
{
157
};
158
159
// Helper c++17 style
160
template
<
class
T>
161
inline
constexpr
bool
is_vector_floating_point_v
=
162
is_vector_floating_point<T>::value
;
163
164
// Generic template handles cases that are not vector type
165
template
<
class
T,
class
=
void
>
struct
is_vector_integral
: std::false_type
166
{
167
};
168
169
// Specialized template handles cases that are vector types
170
template
<
class
T>
171
struct
is_vector_integral
<T, typename
std
::enable_if<is_vector_v<T>>::type>
172
: std::integral_constant<bool, std::is_integral_v<typename T::scalarType>>
173
{
174
};
175
176
// Helper c++17 style
177
template
<
class
T>
178
inline
constexpr
bool
is_vector_integral_v
=
is_vector_integral<T>::value
;
179
180
}
// namespace tinysimd
181
182
#endif
std
STL namespace.
tinysimd::details::void_t
typename make_void< Ts... >::type void_t
Definition
traits.hpp:119
tinysimd
Definition
allocator.hpp:44
tinysimd::is_vector_floating_point_v
constexpr bool is_vector_floating_point_v
Definition
traits.hpp:161
tinysimd::is_vector_integral_v
constexpr bool is_vector_integral_v
Definition
traits.hpp:178
tinysimd::is_load_tag_v
constexpr bool is_load_tag_v
Definition
traits.hpp:84
tinysimd::is_aligned
static constexpr struct tinysimd::is_aligned_t is_aligned
tinysimd::is_not_aligned
static constexpr struct tinysimd::is_not_aligned_t is_not_aligned
tinysimd::is_not_reused
static constexpr struct tinysimd::is_not_reused_t is_not_reused
tinysimd::is_vector_v
constexpr bool is_vector_v
Definition
traits.hpp:142
tinysimd::is_streaming_v
constexpr bool is_streaming_v
Definition
traits.hpp:86
tinysimd::is_requiring_alignment_v
constexpr bool is_requiring_alignment_v
Definition
traits.hpp:88
tinysimd::details::has_alignment
Definition
traits.hpp:106
tinysimd::details::has_scalarType
Definition
traits.hpp:123
tinysimd::details::has_width
Definition
traits.hpp:95
tinysimd::details::make_void
Definition
traits.hpp:116
tinysimd::details::make_void::type
void type
Definition
traits.hpp:117
tinysimd::is_aligned_t
Definition
traits.hpp:45
tinysimd::is_load_tag
Definition
traits.hpp:63
tinysimd::is_not_aligned_t
Definition
traits.hpp:48
tinysimd::is_not_reused_t
Definition
traits.hpp:51
tinysimd::is_requiring_alignment
Definition
traits.hpp:80
tinysimd::is_streaming
Definition
traits.hpp:71
tinysimd::is_vector_floating_point
Definition
traits.hpp:147
tinysimd::is_vector_integral
Definition
traits.hpp:166
tinysimd::is_vector
Definition
traits.hpp:138
Generated on Sun Nov 9 2025 20:16:58 for Nektar++ by
1.9.8