File indexing completed on 2026-05-03 08:13:45
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #ifndef _LIBCPP___CXX03_EXPERIMENTAL___SIMD_VEC_EXT_H
0011 #define _LIBCPP___CXX03_EXPERIMENTAL___SIMD_VEC_EXT_H
0012
0013 #include <__cxx03/__assert>
0014 #include <__cxx03/__bit/bit_ceil.h>
0015 #include <__cxx03/__utility/forward.h>
0016 #include <__cxx03/__utility/integer_sequence.h>
0017 #include <__cxx03/cstddef>
0018 #include <__cxx03/experimental/__config>
0019 #include <__cxx03/experimental/__simd/declaration.h>
0020 #include <__cxx03/experimental/__simd/traits.h>
0021 #include <__cxx03/experimental/__simd/utility.h>
0022
0023 #if _LIBCPP_STD_VER >= 17 && defined(_LIBCPP_ENABLE_EXPERIMENTAL)
0024
0025 _LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL
0026 inline namespace parallelism_v2 {
0027 namespace simd_abi {
0028 template <int _Np>
0029 struct __vec_ext {
0030 static constexpr size_t __simd_size = _Np;
0031 };
0032 }
0033
0034 template <int _Np>
0035 inline constexpr bool is_abi_tag_v<simd_abi::__vec_ext<_Np>> = _Np > 0 && _Np <= 32;
0036
0037 template <class _Tp, int _Np>
0038 struct __simd_storage<_Tp, simd_abi::__vec_ext<_Np>> {
0039 _Tp __data __attribute__((__vector_size__(std::__bit_ceil((sizeof(_Tp) * _Np)))));
0040
0041 _LIBCPP_HIDE_FROM_ABI _Tp __get(size_t __idx) const noexcept {
0042 _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(__idx >= 0 && __idx < _Np, "Index is out of bounds");
0043 return __data[__idx];
0044 }
0045 _LIBCPP_HIDE_FROM_ABI void __set(size_t __idx, _Tp __v) noexcept {
0046 _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(__idx >= 0 && __idx < _Np, "Index is out of bounds");
0047 __data[__idx] = __v;
0048 }
0049 };
0050
0051 template <class _Tp, int _Np>
0052 struct __mask_storage<_Tp, simd_abi::__vec_ext<_Np>>
0053 : __simd_storage<decltype(experimental::__choose_mask_type<_Tp>()), simd_abi::__vec_ext<_Np>> {};
0054
0055 template <class _Tp, int _Np>
0056 struct __simd_operations<_Tp, simd_abi::__vec_ext<_Np>> {
0057 using _SimdStorage = __simd_storage<_Tp, simd_abi::__vec_ext<_Np>>;
0058 using _MaskStorage = __mask_storage<_Tp, simd_abi::__vec_ext<_Np>>;
0059
0060 static _LIBCPP_HIDE_FROM_ABI _SimdStorage __broadcast(_Tp __v) noexcept {
0061 _SimdStorage __result;
0062 for (int __i = 0; __i < _Np; ++__i) {
0063 __result.__set(__i, __v);
0064 }
0065 return __result;
0066 }
0067
0068 template <class _Generator, size_t... _Is>
0069 static _LIBCPP_HIDE_FROM_ABI _SimdStorage __generate_init(_Generator&& __g, std::index_sequence<_Is...>) {
0070 return _SimdStorage{{__g(std::integral_constant<size_t, _Is>())...}};
0071 }
0072
0073 template <class _Generator>
0074 static _LIBCPP_HIDE_FROM_ABI _SimdStorage __generate(_Generator&& __g) noexcept {
0075 return __generate_init(std::forward<_Generator>(__g), std::make_index_sequence<_Np>());
0076 }
0077
0078 template <class _Up>
0079 static _LIBCPP_HIDE_FROM_ABI void __load(_SimdStorage& __s, const _Up* __mem) noexcept {
0080 for (size_t __i = 0; __i < _Np; __i++)
0081 __s.__data[__i] = static_cast<_Tp>(__mem[__i]);
0082 }
0083
0084 template <class _Up>
0085 static _LIBCPP_HIDE_FROM_ABI void __store(_SimdStorage __s, _Up* __mem) noexcept {
0086 for (size_t __i = 0; __i < _Np; __i++)
0087 __mem[__i] = static_cast<_Up>(__s.__data[__i]);
0088 }
0089 };
0090
0091 template <class _Tp, int _Np>
0092 struct __mask_operations<_Tp, simd_abi::__vec_ext<_Np>> {
0093 using _MaskStorage = __mask_storage<_Tp, simd_abi::__vec_ext<_Np>>;
0094
0095 static _LIBCPP_HIDE_FROM_ABI _MaskStorage __broadcast(bool __v) noexcept {
0096 _MaskStorage __result;
0097 auto __all_bits_v = experimental::__set_all_bits<_Tp>(__v);
0098 for (int __i = 0; __i < _Np; ++__i) {
0099 __result.__set(__i, __all_bits_v);
0100 }
0101 return __result;
0102 }
0103
0104 static _LIBCPP_HIDE_FROM_ABI void __load(_MaskStorage& __s, const bool* __mem) noexcept {
0105 for (size_t __i = 0; __i < _Np; __i++)
0106 __s.__data[__i] = experimental::__set_all_bits<_Tp>(__mem[__i]);
0107 }
0108
0109 static _LIBCPP_HIDE_FROM_ABI void __store(_MaskStorage __s, bool* __mem) noexcept {
0110 for (size_t __i = 0; __i < _Np; __i++)
0111 __mem[__i] = static_cast<bool>(__s.__data[__i]);
0112 }
0113 };
0114
0115 }
0116 _LIBCPP_END_NAMESPACE_EXPERIMENTAL
0117
0118 #endif
0119 #endif