Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-31 10:25:46

0001 /*  This file is part of the Vc library. {{{
0002 Copyright © 2013-2015 Matthias Kretz <kretz@kde.org>
0003 
0004 Redistribution and use in source and binary forms, with or without
0005 modification, are permitted provided that the following conditions are met:
0006     * Redistributions of source code must retain the above copyright
0007       notice, this list of conditions and the following disclaimer.
0008     * Redistributions in binary form must reproduce the above copyright
0009       notice, this list of conditions and the following disclaimer in the
0010       documentation and/or other materials provided with the distribution.
0011     * Neither the names of contributing organizations nor the
0012       names of its contributors may be used to endorse or promote products
0013       derived from this software without specific prior written permission.
0014 
0015 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
0016 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
0017 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
0018 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
0019 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
0020 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
0021 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
0022 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
0023 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
0024 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
0025 
0026 }}}*/
0027 
0028 #ifndef VC_TRAITS_TYPE_TRAITS_H_
0029 #define VC_TRAITS_TYPE_TRAITS_H_
0030 
0031 #include <type_traits>
0032 #include "decay.h"
0033 #include "has_no_allocated_data.h"
0034 #include "has_contiguous_storage.h"
0035 #include "is_functor_argument_immutable.h"
0036 #include "is_output_iterator.h"
0037 #include "is_index_sequence.h"
0038 #include "is_implicit_cast_allowed.h"
0039 
0040 namespace Vc_VERSIONED_NAMESPACE
0041 {
0042 // meta-programming helpers
0043 struct enable_if_default_type
0044 {
0045     constexpr enable_if_default_type() {}
0046 };
0047 static constexpr enable_if_default_type nullarg;
0048 template <bool Test, typename T = enable_if_default_type> using enable_if = typename std::enable_if<Test, T>::type;
0049 
0050 template <bool B, class T, class F>
0051 using conditional_t = typename std::conditional<B, T, F>::type;
0052 
0053 template <class T>
0054 using remove_cvref_t =
0055     typename std::remove_cv<typename std::remove_reference<T>::type>::type;
0056 
0057 namespace Traits
0058 {
0059 #include "has_subscript_operator.h"
0060 #include "has_multiply_operator.h"
0061 #include "has_addition_operator.h"
0062 #include "has_equality_operator.h"
0063 
0064 template<typename T> struct is_valid_vector_argument : public std::false_type {};
0065 
0066 template <> struct is_valid_vector_argument<double> : public std::true_type {};
0067 template <> struct is_valid_vector_argument<float>  : public std::true_type {};
0068 template <> struct is_valid_vector_argument<int>    : public std::true_type {};
0069 template <> struct is_valid_vector_argument<unsigned int>   : public std::true_type {};
0070 template <> struct is_valid_vector_argument<short>  : public std::true_type {};
0071 template <> struct is_valid_vector_argument<unsigned short> : public std::true_type {};
0072 
0073 template<typename T> struct is_simd_mask_internal : public std::false_type {};
0074 template<typename T> struct is_simd_vector_internal : public std::false_type {};
0075 template<typename T> struct is_simdarray_internal : public std::false_type {};
0076 template<typename T> struct is_simd_mask_array_internal : public std::false_type {};
0077 template<typename T> struct is_loadstoreflag_internal : public std::false_type {};
0078 
0079 template <typename T, bool = is_simd_vector_internal<T>::value> struct is_integral_internal;
0080 template <typename T, bool = is_simd_vector_internal<T>::value> struct is_floating_point_internal;
0081 template <typename T, bool = is_simd_vector_internal<T>::value> struct is_signed_internal;
0082 template <typename T, bool = is_simd_vector_internal<T>::value> struct is_unsigned_internal;
0083 
0084 template <typename T> struct is_integral_internal      <T, false> : public std::is_integral      <T> {};
0085 template <typename T> struct is_floating_point_internal<T, false> : public std::is_floating_point<T> {};
0086 template <typename T> struct is_signed_internal        <T, false> : public std::is_signed        <T> {};
0087 template <typename T> struct is_unsigned_internal      <T, false> : public std::is_unsigned      <T> {};
0088 
0089 template <typename V> struct is_integral_internal      <V, true> : public std::is_integral      <typename V::EntryType> {};
0090 template <typename V> struct is_floating_point_internal<V, true> : public std::is_floating_point<typename V::EntryType> {};
0091 template <typename V> struct is_signed_internal        <V, true> : public std::is_signed        <typename V::EntryType> {};
0092 template <typename V> struct is_unsigned_internal      <V, true> : public std::is_unsigned      <typename V::EntryType> {};
0093 
0094 template <typename T>
0095 struct is_arithmetic_internal
0096     : public std::integral_constant<
0097           bool,
0098           (is_floating_point_internal<T>::value || is_integral_internal<T>::value)>
0099 {
0100 };
0101 
0102 template <class T, class = void>
0103 struct vector_size_internal : std::integral_constant<std::size_t, 0> {
0104 };
0105 template <class T>
0106 struct vector_size_internal<T, decltype((void)(T::size() > 0))>
0107     : std::integral_constant<std::size_t, T::size()> {
0108 };
0109 
0110 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
0111 
0112 /**
0113  * Identifies any SIMD mask type (independent of implementation or whether it's
0114  * SimdMaskArray<T, N>).
0115  */
0116 template <typename T>
0117 struct is_simd_mask : public std::integral_constant<bool,
0118                                                     (is_simd_mask_internal<decay<T>>::value ||
0119                                                      is_simd_mask_array_internal<decay<T>>::value)>
0120 {
0121 };
0122 
0123 /**
0124  * Identifies any SIMD vector type (independent of implementation or whether it's
0125  * SimdArray<T, N>).
0126  */
0127 template <typename T>
0128 struct is_simd_vector
0129     : public std::integral_constant<bool,
0130                                     (is_simd_vector_internal<decay<T>>::value ||
0131                                      is_simdarray_internal<decay<T>>::value)>
0132 {
0133 };
0134 
0135 /// Identifies any possible SimdArray<T, N> type (independent of const/volatile or reference)
0136 template <typename T>
0137 struct isSimdArray : public is_simdarray_internal<decay<T>>
0138 {
0139 };
0140 
0141 /// Identifies any possible SimdMaskArray<T, N> type (independent of const/volatile or reference)
0142 template <typename T>
0143 struct isSimdMaskArray : public is_simd_mask_array_internal<decay<T>>
0144 {
0145 };
0146 
0147 /// \internal Identifies LoadStoreFlag types
0148 template <typename T> struct is_load_store_flag : public is_loadstoreflag_internal<decay<T>> {};
0149 
0150 /// \internal Identifies a SimdArray type with a single Vector member
0151 template <typename T> struct is_atomic_simdarray_internal : public std::false_type {};
0152 template <typename T> using isAtomicSimdArray = is_atomic_simdarray_internal<decay<T>>;
0153 
0154 /// \internal Identifies a SimdMaskArray type with a single Mask member
0155 template <typename T> struct is_atomic_simd_mask_array_internal : public std::false_type {};
0156 template <typename T> using isAtomicSimdMaskArray = is_atomic_simd_mask_array_internal<decay<T>>;
0157 
0158 /**
0159  * The \p value member will either be the number of SIMD vector entries or 0 if \p T is not a SIMD
0160  * type.
0161  */
0162 template <typename T> struct simd_vector_size : public vector_size_internal<decay<T>> {};
0163 
0164 template <typename T> struct is_integral : public is_integral_internal<decay<T>> {};
0165 template <typename T> struct is_floating_point : public is_floating_point_internal<decay<T>> {};
0166 template <typename T> struct is_arithmetic : public is_arithmetic_internal<decay<T>> {};
0167 template <typename T> struct is_signed : public is_signed_internal<decay<T>> {};
0168 template <typename T> struct is_unsigned : public is_unsigned_internal<decay<T>> {};
0169 
0170 template <typename T, bool IsSimdVector> struct scalar_type_internal { using type = T; };
0171 template <typename T> struct scalar_type_internal<T, true> { using type = typename T::EntryType; };
0172 template <typename T> using scalar_type = typename scalar_type_internal<decay<T>, is_simd_vector<T>::value>::type;
0173 
0174 }  // namespace Traits
0175 }  // namespace Vc
0176 
0177 #include "entry_type_of.h"
0178 
0179 #endif // VC_TRAITS_TYPE_TRAITS_H_