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