Vc  1.3.3-dev
SIMD Vector Classes for C++
type_traits.h
1 /* This file is part of the Vc library. {{{
2 Copyright © 2013-2015 Matthias Kretz <kretz@kde.org>
3 
4 Redistribution and use in source and binary forms, with or without
5 modification, are permitted provided that the following conditions are met:
6  * Redistributions of source code must retain the above copyright
7  notice, this list of conditions and the following disclaimer.
8  * Redistributions in binary form must reproduce the above copyright
9  notice, this list of conditions and the following disclaimer in the
10  documentation and/or other materials provided with the distribution.
11  * Neither the names of contributing organizations nor the
12  names of its contributors may be used to endorse or promote products
13  derived from this software without specific prior written permission.
14 
15 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
19 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 
26 }}}*/
27 
28 #ifndef VC_TRAITS_TYPE_TRAITS_H_
29 #define VC_TRAITS_TYPE_TRAITS_H_
30 
31 #include <type_traits>
32 #include "decay.h"
33 #include "has_no_allocated_data.h"
34 #include "has_contiguous_storage.h"
35 #include "is_initializer_list.h"
36 #include "is_load_arguments.h"
37 #include "is_functor_argument_immutable.h"
38 #include "is_output_iterator.h"
39 #include "is_index_sequence.h"
40 #include "is_implicit_cast_allowed.h"
41 
42 namespace Vc_VERSIONED_NAMESPACE
43 {
44 // meta-programming helpers
45 struct enable_if_default_type
46 {
47  constexpr enable_if_default_type() {}
48 };
49 static constexpr enable_if_default_type nullarg;
50 template <bool Test, typename T = enable_if_default_type> using enable_if = typename std::enable_if<Test, T>::type;
51 
52 namespace Traits
53 {
54 #include "has_subscript_operator.h"
55 #include "has_multiply_operator.h"
56 #include "has_addition_operator.h"
57 #include "has_equality_operator.h"
58 
59 
60 template<typename T> struct is_valid_vector_argument : public std::false_type {};
61 
62 template <> struct is_valid_vector_argument<double> : public std::true_type {};
63 template <> struct is_valid_vector_argument<float> : public std::true_type {};
64 template <> struct is_valid_vector_argument<int> : public std::true_type {};
65 template <> struct is_valid_vector_argument<unsigned int> : public std::true_type {};
66 template <> struct is_valid_vector_argument<short> : public std::true_type {};
67 template <> struct is_valid_vector_argument<unsigned short> : public std::true_type {};
68 
69 template<typename T> struct is_simd_mask_internal : public std::false_type {};
70 template<typename T> struct is_simd_vector_internal : public std::false_type {};
71 template<typename T> struct is_subscript_operation_internal : public std::false_type {};
72 template<typename T> struct is_simdarray_internal : public std::false_type {};
73 template<typename T> struct is_simd_mask_array_internal : public std::false_type {};
74 template<typename T> struct is_loadstoreflag_internal : public std::false_type {};
75 
76 #include "is_gather_signature.h"
77 
78 template <std::size_t, typename... Args> struct is_cast_arguments_internal : public std::false_type {};
79 template <typename Arg>
80 struct is_cast_arguments_internal<1, Arg> : public std::integral_constant<
81  bool,
82  is_simdarray_internal<Arg>::value ||
83  is_simd_vector_internal<Arg>::value>
84 {
85 };
86 
87 template <typename T, bool = is_simd_vector_internal<T>::value> struct is_integral_internal;
88 template <typename T, bool = is_simd_vector_internal<T>::value> struct is_floating_point_internal;
89 template <typename T, bool = is_simd_vector_internal<T>::value> struct is_signed_internal;
90 template <typename T, bool = is_simd_vector_internal<T>::value> struct is_unsigned_internal;
91 
92 template <typename T> struct is_integral_internal <T, false> : public std::is_integral <T> {};
93 template <typename T> struct is_floating_point_internal<T, false> : public std::is_floating_point<T> {};
94 template <typename T> struct is_signed_internal <T, false> : public std::is_signed <T> {};
95 template <typename T> struct is_unsigned_internal <T, false> : public std::is_unsigned <T> {};
96 
97 template <typename V> struct is_integral_internal <V, true> : public std::is_integral <typename V::EntryType> {};
98 template <typename V> struct is_floating_point_internal<V, true> : public std::is_floating_point<typename V::EntryType> {};
99 template <typename V> struct is_signed_internal <V, true> : public std::is_signed <typename V::EntryType> {};
100 template <typename V> struct is_unsigned_internal <V, true> : public std::is_unsigned <typename V::EntryType> {};
101 
102 template <typename T>
103 struct is_arithmetic_internal
104  : public std::integral_constant<
105  bool,
106  (is_floating_point_internal<T>::value || is_integral_internal<T>::value)>
107 {
108 };
109 
110 template <typename T,
111  bool = (is_simd_vector_internal<T>::value || is_simd_mask_internal<T>::value ||
112  is_simdarray_internal<T>::value ||
113  is_simd_mask_array_internal<T>::value)>
114 struct vector_size_internal;
115 
116 template <typename T>
117 struct vector_size_internal<T, true> : public std::integral_constant<std::size_t, T::Size>
118 {
119 };
120 template <typename T>
121 struct vector_size_internal<T, false> : public std::integral_constant<std::size_t, 0>
122 {
123 };
124 
126 
131 template <typename T>
132 struct is_simd_mask : public std::integral_constant<bool,
133  (is_simd_mask_internal<decay<T>>::value ||
134  is_simd_mask_array_internal<decay<T>>::value)>
135 {
136 };
137 
142 template <typename T>
144  : public std::integral_constant<bool,
145  (is_simd_vector_internal<decay<T>>::value ||
146  is_simdarray_internal<decay<T>>::value)>
147 {
148 };
149 
151 template <typename T>
152 struct isSimdArray : public is_simdarray_internal<decay<T>>
153 {
154 };
155 
157 template <typename T>
158 struct isSimdMaskArray : public is_simd_mask_array_internal<decay<T>>
159 {
160 };
161 
163 template <typename T> struct is_subscript_operation : public is_subscript_operation_internal<decay<T>> {};
165 template <typename T> struct is_load_store_flag : public is_loadstoreflag_internal<decay<T>> {};
167 template <typename... Args> struct is_cast_arguments : public is_cast_arguments_internal<sizeof...(Args), decay<Args>...> {};
168 
170 template <typename T> struct is_atomic_simdarray_internal : public std::false_type {};
171 template <typename T> using isAtomicSimdArray = is_atomic_simdarray_internal<decay<T>>;
172 
174 template <typename T> struct is_atomic_simd_mask_array_internal : public std::false_type {};
175 template <typename T> using isAtomicSimdMaskArray = is_atomic_simd_mask_array_internal<decay<T>>;
176 
181 template <typename T> struct simd_vector_size : public vector_size_internal<decay<T>> {};
182 
183 template <typename T> struct is_integral : public is_integral_internal<decay<T>> {};
184 template <typename T> struct is_floating_point : public is_floating_point_internal<decay<T>> {};
185 template <typename T> struct is_arithmetic : public is_arithmetic_internal<decay<T>> {};
186 template <typename T> struct is_signed : public is_signed_internal<decay<T>> {};
187 template <typename T> struct is_unsigned : public is_unsigned_internal<decay<T>> {};
188 
189 template <typename T, bool IsSimdVector> struct scalar_type_internal { using type = T; };
190 template <typename T> struct scalar_type_internal<T, true> { using type = typename T::EntryType; };
191 template <typename T> using scalar_type = typename scalar_type_internal<decay<T>, is_simd_vector<T>::value>::type;
192 
193 } // namespace Traits
194 } // namespace Vc
195 
196 #include "entry_type_of.h"
197 
198 #endif // VC_TRAITS_TYPE_TRAITS_H_
Identifies any possible SimdArray<T, N> type (independent of const/volatile or reference) ...
Definition: type_traits.h:152
Identifies any possible SimdMaskArray<T, N> type (independent of const/volatile or reference) ...
Definition: type_traits.h:158
The value member will either be the number of SIMD vector entries or 0 if T is not a SIMD type...
Definition: type_traits.h:181
Identifies any SIMD vector type (independent of implementation or whether it&#39;s SimdArray<T, N>).
Definition: type_traits.h:143
Identifies any SIMD mask type (independent of implementation or whether it&#39;s SimdMaskArray<T, N>).
Definition: type_traits.h:132