Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-03 08:14:08

0001 // -*- C++ -*-
0002 //===----------------------------------------------------------------------===//
0003 //
0004 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0005 // See https://llvm.org/LICENSE.txt for license information.
0006 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0007 //
0008 //===----------------------------------------------------------------------===//
0009 
0010 #ifndef _LIBCPP_EXPERIMENTAL___SIMD_UTILITY_H
0011 #define _LIBCPP_EXPERIMENTAL___SIMD_UTILITY_H
0012 
0013 #include <__config>
0014 #include <__cstddef/size_t.h>
0015 #include <__type_traits/is_arithmetic.h>
0016 #include <__type_traits/is_const.h>
0017 #include <__type_traits/is_constant_evaluated.h>
0018 #include <__type_traits/is_convertible.h>
0019 #include <__type_traits/is_same.h>
0020 #include <__type_traits/is_unsigned.h>
0021 #include <__type_traits/is_volatile.h>
0022 #include <__type_traits/void_t.h>
0023 #include <__utility/declval.h>
0024 #include <__utility/integer_sequence.h>
0025 #include <cstdint>
0026 #include <limits>
0027 
0028 _LIBCPP_PUSH_MACROS
0029 #include <__undef_macros>
0030 
0031 #if _LIBCPP_STD_VER >= 17 && defined(_LIBCPP_ENABLE_EXPERIMENTAL)
0032 
0033 _LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL
0034 inline namespace parallelism_v2 {
0035 template <class _Tp>
0036 inline constexpr bool __is_vectorizable_v =
0037     is_arithmetic_v<_Tp> && !is_const_v<_Tp> && !is_volatile_v<_Tp> && !is_same_v<_Tp, bool>;
0038 
0039 template <class _Tp>
0040 _LIBCPP_HIDE_FROM_ABI auto __choose_mask_type() {
0041   if constexpr (sizeof(_Tp) == 1) {
0042     return uint8_t{};
0043   } else if constexpr (sizeof(_Tp) == 2) {
0044     return uint16_t{};
0045   } else if constexpr (sizeof(_Tp) == 4) {
0046     return uint32_t{};
0047   } else if constexpr (sizeof(_Tp) == 8) {
0048     return uint64_t{};
0049   }
0050 #  if _LIBCPP_HAS_INT128
0051   else if constexpr (sizeof(_Tp) == 16) {
0052     return __uint128_t{};
0053   }
0054 #  endif
0055   else
0056     static_assert(sizeof(_Tp) == 0, "Unexpected size");
0057 }
0058 
0059 template <class _Tp>
0060 _LIBCPP_HIDE_FROM_ABI auto constexpr __set_all_bits(bool __v) {
0061   return __v ? (numeric_limits<decltype(__choose_mask_type<_Tp>())>::max()) : 0;
0062 }
0063 
0064 template <class _From, class _To, class = void>
0065 inline constexpr bool __is_non_narrowing_convertible_v = false;
0066 
0067 template <class _From, class _To>
0068 inline constexpr bool __is_non_narrowing_convertible_v<_From, _To, std::void_t<decltype(_To{std::declval<_From>()})>> =
0069     true;
0070 
0071 template <class _Tp, class _Up>
0072 inline constexpr bool __can_broadcast_v =
0073     (__is_vectorizable_v<_Up> && __is_non_narrowing_convertible_v<_Up, _Tp>) ||
0074     (!__is_vectorizable_v<_Up> && is_convertible_v<_Up, _Tp>) || is_same_v<_Up, int> ||
0075     (is_same_v<_Up, unsigned int> && is_unsigned_v<_Tp>);
0076 
0077 template <class _Tp, class _Generator, std::size_t _Idx, class = void>
0078 inline constexpr bool __is_well_formed = false;
0079 
0080 template <class _Tp, class _Generator, std::size_t _Idx>
0081 inline constexpr bool
0082     __is_well_formed<_Tp,
0083                      _Generator,
0084                      _Idx,
0085                      std::void_t<decltype(std::declval<_Generator>()(integral_constant<size_t, _Idx>()))>> =
0086         __can_broadcast_v<_Tp, decltype(std::declval<_Generator>()(integral_constant<size_t, _Idx>()))>;
0087 
0088 template <class _Tp, class _Generator, std::size_t... _Idxes>
0089 _LIBCPP_HIDE_FROM_ABI constexpr bool __can_generate(index_sequence<_Idxes...>) {
0090   return (true && ... && __is_well_formed<_Tp, _Generator, _Idxes>);
0091 }
0092 
0093 template <class _Tp, class _Generator, std::size_t _Size>
0094 inline constexpr bool __can_generate_v = experimental::__can_generate<_Tp, _Generator>(make_index_sequence<_Size>());
0095 
0096 } // namespace parallelism_v2
0097 _LIBCPP_END_NAMESPACE_EXPERIMENTAL
0098 
0099 #endif // _LIBCPP_STD_VER >= 17 && defined(_LIBCPP_ENABLE_EXPERIMENTAL)
0100 
0101 _LIBCPP_POP_MACROS
0102 
0103 #endif // _LIBCPP_EXPERIMENTAL___SIMD_UTILITY_H