mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-06-28 07:18:30 +00:00
Release Cosmopolitan v3.6.0
This release is an atomic upgrade to GCC 14.1.0 with C23 and C++23
This commit is contained in:
parent
62ace3623a
commit
5660ec4741
1585 changed files with 117353 additions and 271644 deletions
75
third_party/libcxx/experimental/__simd/aligned_tag.h
vendored
Normal file
75
third_party/libcxx/experimental/__simd/aligned_tag.h
vendored
Normal file
|
@ -0,0 +1,75 @@
|
|||
// -*- C++ -*-
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef _LIBCPP_EXPERIMENTAL___SIMD_ALIGNED_TAG_H
|
||||
#define _LIBCPP_EXPERIMENTAL___SIMD_ALIGNED_TAG_H
|
||||
|
||||
#include <__memory/assume_aligned.h>
|
||||
#include <__type_traits/remove_const.h>
|
||||
#include <cstddef>
|
||||
#include <experimental/__config>
|
||||
#include <experimental/__simd/traits.h>
|
||||
|
||||
#if _LIBCPP_STD_VER >= 17 && defined(_LIBCPP_ENABLE_EXPERIMENTAL)
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL
|
||||
inline namespace parallelism_v2 {
|
||||
// memory alignment
|
||||
struct element_aligned_tag {
|
||||
template <class _Tp, class _Up = typename _Tp::value_type>
|
||||
static constexpr size_t __alignment = alignof(_Up);
|
||||
|
||||
template <class _Tp, class _Up>
|
||||
static _LIBCPP_HIDE_FROM_ABI constexpr _Up* __apply(_Up* __ptr) {
|
||||
return __ptr;
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
inline constexpr bool is_simd_flag_type_v<element_aligned_tag> = true;
|
||||
|
||||
struct vector_aligned_tag {
|
||||
template <class _Tp, class _Up = typename _Tp::value_type>
|
||||
static constexpr size_t __alignment = memory_alignment_v<_Tp, remove_const_t<_Up>>;
|
||||
|
||||
template <class _Tp, class _Up>
|
||||
static _LIBCPP_HIDE_FROM_ABI constexpr _Up* __apply(_Up* __ptr) {
|
||||
return std::__assume_aligned<__alignment<_Tp, _Up>, _Up>(__ptr);
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
inline constexpr bool is_simd_flag_type_v<vector_aligned_tag> = true;
|
||||
|
||||
template <size_t _Np>
|
||||
struct overaligned_tag {
|
||||
template <class _Tp, class _Up = typename _Tp::value_type>
|
||||
static constexpr size_t __alignment = _Np;
|
||||
|
||||
template <class _Tp, class _Up>
|
||||
static _LIBCPP_HIDE_FROM_ABI constexpr _Up* __apply(_Up* __ptr) {
|
||||
return std::__assume_aligned<__alignment<_Tp, _Up>, _Up>(__ptr);
|
||||
}
|
||||
};
|
||||
|
||||
template <size_t _Np>
|
||||
inline constexpr bool is_simd_flag_type_v<overaligned_tag<_Np>> = true;
|
||||
|
||||
inline constexpr element_aligned_tag element_aligned{};
|
||||
|
||||
inline constexpr vector_aligned_tag vector_aligned{};
|
||||
|
||||
template <size_t _Np>
|
||||
inline constexpr overaligned_tag<_Np> overaligned{};
|
||||
|
||||
} // namespace parallelism_v2
|
||||
_LIBCPP_END_NAMESPACE_EXPERIMENTAL
|
||||
|
||||
#endif // _LIBCPP_STD_VER >= 17 && defined(_LIBCPP_ENABLE_EXPERIMENTAL)
|
||||
#endif // _LIBCPP_EXPERIMENTAL___SIMD_ALIGNED_TAG_H
|
81
third_party/libcxx/experimental/__simd/declaration.h
vendored
Normal file
81
third_party/libcxx/experimental/__simd/declaration.h
vendored
Normal file
|
@ -0,0 +1,81 @@
|
|||
// -*- C++ -*-
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef _LIBCPP_EXPERIMENTAL___SIMD_DECLARATION_H
|
||||
#define _LIBCPP_EXPERIMENTAL___SIMD_DECLARATION_H
|
||||
|
||||
#include <cstddef>
|
||||
#include <experimental/__config>
|
||||
|
||||
#if _LIBCPP_STD_VER >= 17 && defined(_LIBCPP_ENABLE_EXPERIMENTAL)
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL
|
||||
inline namespace parallelism_v2 {
|
||||
namespace simd_abi {
|
||||
template <int>
|
||||
struct __vec_ext;
|
||||
struct __scalar;
|
||||
|
||||
using scalar = __scalar;
|
||||
|
||||
// TODO: make this platform dependent
|
||||
template <int _Np>
|
||||
using fixed_size = __vec_ext<_Np>;
|
||||
|
||||
template <class _Tp>
|
||||
inline constexpr int max_fixed_size = 32;
|
||||
|
||||
// TODO: make this platform dependent
|
||||
template <class _Tp>
|
||||
using compatible = __vec_ext<16 / sizeof(_Tp)>;
|
||||
|
||||
// TODO: make this platform dependent
|
||||
template <class _Tp>
|
||||
using native = __vec_ext<_LIBCPP_NATIVE_SIMD_WIDTH_IN_BYTES / sizeof(_Tp)>;
|
||||
|
||||
// TODO: make this platform dependent
|
||||
template <class _Tp, size_t _Np, class... _Abis>
|
||||
struct deduce {
|
||||
using type = fixed_size<_Np>;
|
||||
};
|
||||
|
||||
// TODO: make this platform dependent
|
||||
template <class _Tp, size_t _Np, class... _Abis>
|
||||
using deduce_t = typename deduce<_Tp, _Np, _Abis...>::type;
|
||||
|
||||
} // namespace simd_abi
|
||||
|
||||
template <class _Tp, class _Abi>
|
||||
struct __simd_storage;
|
||||
|
||||
template <class _Tp, class _Abi>
|
||||
struct __mask_storage;
|
||||
|
||||
template <class _Tp, class _Abi>
|
||||
struct __simd_operations;
|
||||
|
||||
template <class _Tp, class _Abi>
|
||||
struct __mask_operations;
|
||||
|
||||
struct element_aligned_tag;
|
||||
struct vector_aligned_tag;
|
||||
template <size_t>
|
||||
struct overaligned_tag;
|
||||
|
||||
template <class _Tp, class _Abi = simd_abi::compatible<_Tp>>
|
||||
class simd;
|
||||
|
||||
template <class _Tp, class _Abi = simd_abi::compatible<_Tp>>
|
||||
class simd_mask;
|
||||
|
||||
} // namespace parallelism_v2
|
||||
_LIBCPP_END_NAMESPACE_EXPERIMENTAL
|
||||
|
||||
#endif // _LIBCPP_STD_VER >= 17 && defined(_LIBCPP_ENABLE_EXPERIMENTAL)
|
||||
#endif // _LIBCPP_EXPERIMENTAL___SIMD_DECLARATION_H
|
105
third_party/libcxx/experimental/__simd/reference.h
vendored
Normal file
105
third_party/libcxx/experimental/__simd/reference.h
vendored
Normal file
|
@ -0,0 +1,105 @@
|
|||
// -*- C++ -*-
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef _LIBCPP_EXPERIMENTAL___SIMD_REFERENCE_H
|
||||
#define _LIBCPP_EXPERIMENTAL___SIMD_REFERENCE_H
|
||||
|
||||
#include <__type_traits/is_assignable.h>
|
||||
#include <__type_traits/is_same.h>
|
||||
#include <__utility/forward.h>
|
||||
#include <__utility/move.h>
|
||||
#include <cstddef>
|
||||
#include <experimental/__config>
|
||||
#include <experimental/__simd/utility.h>
|
||||
|
||||
_LIBCPP_PUSH_MACROS
|
||||
#include <__undef_macros>
|
||||
|
||||
#if _LIBCPP_STD_VER >= 17 && defined(_LIBCPP_ENABLE_EXPERIMENTAL)
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL
|
||||
inline namespace parallelism_v2 {
|
||||
template <class _Tp, class _Storage, class _Vp>
|
||||
class __simd_reference {
|
||||
template <class, class>
|
||||
friend class simd;
|
||||
template <class, class>
|
||||
friend class simd_mask;
|
||||
|
||||
_Storage& __s_;
|
||||
size_t __idx_;
|
||||
|
||||
_LIBCPP_HIDE_FROM_ABI __simd_reference(_Storage& __s, size_t __idx) : __s_(__s), __idx_(__idx) {}
|
||||
|
||||
_LIBCPP_HIDE_FROM_ABI _Vp __get() const noexcept { return __s_.__get(__idx_); }
|
||||
|
||||
_LIBCPP_HIDE_FROM_ABI void __set(_Vp __v) {
|
||||
if constexpr (is_same_v<_Vp, bool>)
|
||||
__s_.__set(__idx_, experimental::__set_all_bits<_Tp>(__v));
|
||||
else
|
||||
__s_.__set(__idx_, __v);
|
||||
}
|
||||
|
||||
public:
|
||||
using value_type = _Vp;
|
||||
|
||||
__simd_reference() = delete;
|
||||
__simd_reference(const __simd_reference&) = delete;
|
||||
|
||||
_LIBCPP_HIDE_FROM_ABI operator value_type() const noexcept { return __get(); }
|
||||
|
||||
template <class _Up, enable_if_t<is_assignable_v<value_type&, _Up&&>, int> = 0>
|
||||
_LIBCPP_HIDE_FROM_ABI __simd_reference operator=(_Up&& __v) && noexcept {
|
||||
__set(static_cast<value_type>(std::forward<_Up>(__v)));
|
||||
return {__s_, __idx_};
|
||||
}
|
||||
|
||||
// Note: This approach might not fully align with the specification,
|
||||
// which might be a wording defect. (https://wg21.link/N4808 section 9.6.3)
|
||||
template <class _Tp1, class _Storage1, class _Vp1>
|
||||
friend void
|
||||
swap(__simd_reference<_Tp1, _Storage1, _Vp1>&& __a, __simd_reference<_Tp1, _Storage1, _Vp1>&& __b) noexcept;
|
||||
|
||||
template <class _Tp1, class _Storage1, class _Vp1>
|
||||
friend void swap(_Vp1& __a, __simd_reference<_Tp1, _Storage1, _Vp1>&& __b) noexcept;
|
||||
|
||||
template <class _Tp1, class _Storage1, class _Vp1>
|
||||
friend void swap(__simd_reference<_Tp1, _Storage1, _Vp1>&& __a, _Vp1& __b) noexcept;
|
||||
};
|
||||
|
||||
template <class _Tp, class _Storage, class _Vp>
|
||||
_LIBCPP_HIDE_FROM_ABI void
|
||||
swap(__simd_reference<_Tp, _Storage, _Vp>&& __a, __simd_reference<_Tp, _Storage, _Vp>&& __b) noexcept {
|
||||
_Vp __tmp(std::move(__a));
|
||||
std::move(__a) = std::move(__b);
|
||||
std::move(__b) = std::move(__tmp);
|
||||
}
|
||||
|
||||
template <class _Tp, class _Storage, class _Vp>
|
||||
_LIBCPP_HIDE_FROM_ABI void swap(_Vp& __a, __simd_reference<_Tp, _Storage, _Vp>&& __b) noexcept {
|
||||
_Vp __tmp(std::move(__a));
|
||||
__a = std::move(__b);
|
||||
std::move(__b) = std::move(__tmp);
|
||||
}
|
||||
|
||||
template <class _Tp, class _Storage, class _Vp>
|
||||
_LIBCPP_HIDE_FROM_ABI void swap(__simd_reference<_Tp, _Storage, _Vp>&& __a, _Vp& __b) noexcept {
|
||||
_Vp __tmp(std::move(__a));
|
||||
std::move(__a) = std::move(__b);
|
||||
__b = std::move(__tmp);
|
||||
}
|
||||
|
||||
} // namespace parallelism_v2
|
||||
_LIBCPP_END_NAMESPACE_EXPERIMENTAL
|
||||
|
||||
#endif // _LIBCPP_STD_VER >= 17 && defined(_LIBCPP_ENABLE_EXPERIMENTAL)
|
||||
|
||||
_LIBCPP_POP_MACROS
|
||||
|
||||
#endif // _LIBCPP_EXPERIMENTAL___SIMD_REFERENCE_H
|
87
third_party/libcxx/experimental/__simd/scalar.h
vendored
Normal file
87
third_party/libcxx/experimental/__simd/scalar.h
vendored
Normal file
|
@ -0,0 +1,87 @@
|
|||
// -*- C++ -*-
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef _LIBCPP_EXPERIMENTAL___SIMD_SCALAR_H
|
||||
#define _LIBCPP_EXPERIMENTAL___SIMD_SCALAR_H
|
||||
|
||||
#include <__assert>
|
||||
#include <cstddef>
|
||||
#include <experimental/__config>
|
||||
#include <experimental/__simd/declaration.h>
|
||||
#include <experimental/__simd/traits.h>
|
||||
|
||||
#if _LIBCPP_STD_VER >= 17 && defined(_LIBCPP_ENABLE_EXPERIMENTAL)
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL
|
||||
inline namespace parallelism_v2 {
|
||||
namespace simd_abi {
|
||||
struct __scalar {
|
||||
static constexpr size_t __simd_size = 1;
|
||||
};
|
||||
} // namespace simd_abi
|
||||
|
||||
template <>
|
||||
inline constexpr bool is_abi_tag_v<simd_abi::__scalar> = true;
|
||||
|
||||
template <class _Tp>
|
||||
struct __simd_storage<_Tp, simd_abi::__scalar> {
|
||||
_Tp __data;
|
||||
|
||||
_LIBCPP_HIDE_FROM_ABI _Tp __get([[maybe_unused]] size_t __idx) const noexcept {
|
||||
_LIBCPP_ASSERT_UNCATEGORIZED(__idx == 0, "Index is out of bounds");
|
||||
return __data;
|
||||
}
|
||||
_LIBCPP_HIDE_FROM_ABI void __set([[maybe_unused]] size_t __idx, _Tp __v) noexcept {
|
||||
_LIBCPP_ASSERT_UNCATEGORIZED(__idx == 0, "Index is out of bounds");
|
||||
__data = __v;
|
||||
}
|
||||
};
|
||||
|
||||
template <class _Tp>
|
||||
struct __mask_storage<_Tp, simd_abi::__scalar> : __simd_storage<bool, simd_abi::__scalar> {};
|
||||
|
||||
template <class _Tp>
|
||||
struct __simd_operations<_Tp, simd_abi::__scalar> {
|
||||
using _SimdStorage = __simd_storage<_Tp, simd_abi::__scalar>;
|
||||
using _MaskStorage = __mask_storage<_Tp, simd_abi::__scalar>;
|
||||
|
||||
static _LIBCPP_HIDE_FROM_ABI _SimdStorage __broadcast(_Tp __v) noexcept { return {__v}; }
|
||||
|
||||
template <class _Generator>
|
||||
static _LIBCPP_HIDE_FROM_ABI _SimdStorage __generate(_Generator&& __g) noexcept {
|
||||
return {__g(std::integral_constant<size_t, 0>())};
|
||||
}
|
||||
|
||||
template <class _Up>
|
||||
static _LIBCPP_HIDE_FROM_ABI void __load(_SimdStorage& __s, const _Up* __mem) noexcept {
|
||||
__s.__data = static_cast<_Tp>(__mem[0]);
|
||||
}
|
||||
|
||||
template <class _Up>
|
||||
static _LIBCPP_HIDE_FROM_ABI void __store(_SimdStorage __s, _Up* __mem) noexcept {
|
||||
*__mem = static_cast<_Up>(__s.__data);
|
||||
}
|
||||
};
|
||||
|
||||
template <class _Tp>
|
||||
struct __mask_operations<_Tp, simd_abi::__scalar> {
|
||||
using _MaskStorage = __mask_storage<_Tp, simd_abi::__scalar>;
|
||||
|
||||
static _LIBCPP_HIDE_FROM_ABI _MaskStorage __broadcast(bool __v) noexcept { return {__v}; }
|
||||
|
||||
static _LIBCPP_HIDE_FROM_ABI void __load(_MaskStorage& __s, const bool* __mem) noexcept { __s.__data = __mem[0]; }
|
||||
|
||||
static _LIBCPP_HIDE_FROM_ABI void __store(_MaskStorage __s, bool* __mem) noexcept { __mem[0] = __s.__data; }
|
||||
};
|
||||
|
||||
} // namespace parallelism_v2
|
||||
_LIBCPP_END_NAMESPACE_EXPERIMENTAL
|
||||
|
||||
#endif // _LIBCPP_STD_VER >= 17 && defined(_LIBCPP_ENABLE_EXPERIMENTAL)
|
||||
#endif // _LIBCPP_EXPERIMENTAL___SIMD_SCALAR_H
|
102
third_party/libcxx/experimental/__simd/simd.h
vendored
Normal file
102
third_party/libcxx/experimental/__simd/simd.h
vendored
Normal file
|
@ -0,0 +1,102 @@
|
|||
// -*- C++ -*-
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef _LIBCPP_EXPERIMENTAL___SIMD_SIMD_H
|
||||
#define _LIBCPP_EXPERIMENTAL___SIMD_SIMD_H
|
||||
|
||||
#include <__type_traits/is_same.h>
|
||||
#include <__type_traits/remove_cvref.h>
|
||||
#include <__utility/forward.h>
|
||||
#include <cstddef>
|
||||
#include <experimental/__config>
|
||||
#include <experimental/__simd/declaration.h>
|
||||
#include <experimental/__simd/reference.h>
|
||||
#include <experimental/__simd/traits.h>
|
||||
#include <experimental/__simd/utility.h>
|
||||
|
||||
#if _LIBCPP_STD_VER >= 17 && defined(_LIBCPP_ENABLE_EXPERIMENTAL)
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL
|
||||
inline namespace parallelism_v2 {
|
||||
|
||||
// class template simd [simd.class]
|
||||
// TODO: implement simd class
|
||||
template <class _Tp, class _Abi>
|
||||
class simd {
|
||||
using _Impl = __simd_operations<_Tp, _Abi>;
|
||||
using _Storage = typename _Impl::_SimdStorage;
|
||||
|
||||
_Storage __s_;
|
||||
|
||||
public:
|
||||
using value_type = _Tp;
|
||||
using reference = __simd_reference<_Tp, _Storage, value_type>;
|
||||
using mask_type = simd_mask<_Tp, _Abi>;
|
||||
using abi_type = _Abi;
|
||||
|
||||
static _LIBCPP_HIDE_FROM_ABI constexpr size_t size() noexcept { return simd_size_v<value_type, abi_type>; }
|
||||
|
||||
_LIBCPP_HIDE_FROM_ABI simd() noexcept = default;
|
||||
|
||||
// broadcast constructor
|
||||
template <class _Up, enable_if_t<__can_broadcast_v<value_type, __remove_cvref_t<_Up>>, int> = 0>
|
||||
_LIBCPP_HIDE_FROM_ABI simd(_Up&& __v) noexcept : __s_(_Impl::__broadcast(static_cast<value_type>(__v))) {}
|
||||
|
||||
// implicit type conversion constructor
|
||||
template <class _Up,
|
||||
enable_if_t<!is_same_v<_Up, _Tp> && is_same_v<abi_type, simd_abi::fixed_size<size()>> &&
|
||||
__is_non_narrowing_convertible_v<_Up, value_type>,
|
||||
int> = 0>
|
||||
_LIBCPP_HIDE_FROM_ABI simd(const simd<_Up, simd_abi::fixed_size<size()>>& __v) noexcept {
|
||||
for (size_t __i = 0; __i < size(); __i++) {
|
||||
(*this)[__i] = static_cast<value_type>(__v[__i]);
|
||||
}
|
||||
}
|
||||
|
||||
// generator constructor
|
||||
template <class _Generator, enable_if_t<__can_generate_v<value_type, _Generator, size()>, int> = 0>
|
||||
explicit _LIBCPP_HIDE_FROM_ABI simd(_Generator&& __g) noexcept
|
||||
: __s_(_Impl::__generate(std::forward<_Generator>(__g))) {}
|
||||
|
||||
// load constructor
|
||||
template <class _Up, class _Flags, enable_if_t<__is_vectorizable_v<_Up> && is_simd_flag_type_v<_Flags>, int> = 0>
|
||||
_LIBCPP_HIDE_FROM_ABI simd(const _Up* __mem, _Flags) {
|
||||
_Impl::__load(__s_, _Flags::template __apply<simd>(__mem));
|
||||
}
|
||||
|
||||
// copy functions
|
||||
template <class _Up, class _Flags, enable_if_t<__is_vectorizable_v<_Up> && is_simd_flag_type_v<_Flags>, int> = 0>
|
||||
_LIBCPP_HIDE_FROM_ABI void copy_from(const _Up* __mem, _Flags) {
|
||||
_Impl::__load(__s_, _Flags::template __apply<simd>(__mem));
|
||||
}
|
||||
|
||||
template <class _Up, class _Flags, enable_if_t<__is_vectorizable_v<_Up> && is_simd_flag_type_v<_Flags>, int> = 0>
|
||||
_LIBCPP_HIDE_FROM_ABI void copy_to(_Up* __mem, _Flags) const {
|
||||
_Impl::__store(__s_, _Flags::template __apply<simd>(__mem));
|
||||
}
|
||||
|
||||
// scalar access [simd.subscr]
|
||||
_LIBCPP_HIDE_FROM_ABI reference operator[](size_t __i) noexcept { return reference(__s_, __i); }
|
||||
_LIBCPP_HIDE_FROM_ABI value_type operator[](size_t __i) const noexcept { return __s_.__get(__i); }
|
||||
};
|
||||
|
||||
template <class _Tp, class _Abi>
|
||||
inline constexpr bool is_simd_v<simd<_Tp, _Abi>> = true;
|
||||
|
||||
template <class _Tp>
|
||||
using native_simd = simd<_Tp, simd_abi::native<_Tp>>;
|
||||
|
||||
template <class _Tp, int _Np>
|
||||
using fixed_size_simd = simd<_Tp, simd_abi::fixed_size<_Np>>;
|
||||
|
||||
} // namespace parallelism_v2
|
||||
_LIBCPP_END_NAMESPACE_EXPERIMENTAL
|
||||
|
||||
#endif // _LIBCPP_STD_VER >= 17 && defined(_LIBCPP_ENABLE_EXPERIMENTAL)
|
||||
#endif // _LIBCPP_EXPERIMENTAL___SIMD_SIMD_H
|
90
third_party/libcxx/experimental/__simd/simd_mask.h
vendored
Normal file
90
third_party/libcxx/experimental/__simd/simd_mask.h
vendored
Normal file
|
@ -0,0 +1,90 @@
|
|||
// -*- C++ -*-
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef _LIBCPP_EXPERIMENTAL___SIMD_SIMD_MASK_H
|
||||
#define _LIBCPP_EXPERIMENTAL___SIMD_SIMD_MASK_H
|
||||
|
||||
#include <__type_traits/is_same.h>
|
||||
#include <cstddef>
|
||||
#include <experimental/__config>
|
||||
#include <experimental/__simd/declaration.h>
|
||||
#include <experimental/__simd/reference.h>
|
||||
#include <experimental/__simd/traits.h>
|
||||
|
||||
#if _LIBCPP_STD_VER >= 17 && defined(_LIBCPP_ENABLE_EXPERIMENTAL)
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL
|
||||
inline namespace parallelism_v2 {
|
||||
|
||||
// class template simd_mask [simd.mask.class]
|
||||
// TODO: implement simd_mask class
|
||||
template <class _Tp, class _Abi>
|
||||
class simd_mask {
|
||||
using _Impl = __mask_operations<_Tp, _Abi>;
|
||||
using _Storage = typename _Impl::_MaskStorage;
|
||||
|
||||
_Storage __s_;
|
||||
|
||||
public:
|
||||
using value_type = bool;
|
||||
using reference = __simd_reference<_Tp, _Storage, value_type>;
|
||||
using simd_type = simd<_Tp, _Abi>;
|
||||
using abi_type = _Abi;
|
||||
|
||||
static _LIBCPP_HIDE_FROM_ABI constexpr size_t size() noexcept { return simd_type::size(); }
|
||||
|
||||
_LIBCPP_HIDE_FROM_ABI simd_mask() noexcept = default;
|
||||
|
||||
// broadcast constructor
|
||||
_LIBCPP_HIDE_FROM_ABI explicit simd_mask(value_type __v) noexcept : __s_(_Impl::__broadcast(__v)) {}
|
||||
|
||||
// implicit type conversion constructor
|
||||
template <class _Up, enable_if_t<!is_same_v<_Up, _Tp> && is_same_v<abi_type, simd_abi::fixed_size<size()>>, int> = 0>
|
||||
_LIBCPP_HIDE_FROM_ABI simd_mask(const simd_mask<_Up, simd_abi::fixed_size<size()>>& __v) noexcept {
|
||||
for (size_t __i = 0; __i < size(); __i++) {
|
||||
(*this)[__i] = __v[__i];
|
||||
}
|
||||
}
|
||||
|
||||
// load constructor
|
||||
template <class _Flags, enable_if_t<is_simd_flag_type_v<_Flags>, int> = 0>
|
||||
_LIBCPP_HIDE_FROM_ABI simd_mask(const value_type* __mem, _Flags) {
|
||||
_Impl::__load(__s_, _Flags::template __apply<simd_mask>(__mem));
|
||||
}
|
||||
|
||||
// copy functions
|
||||
template <class _Flags, enable_if_t<is_simd_flag_type_v<_Flags>, int> = 0>
|
||||
_LIBCPP_HIDE_FROM_ABI void copy_from(const value_type* __mem, _Flags) {
|
||||
_Impl::__load(__s_, _Flags::template __apply<simd_mask>(__mem));
|
||||
}
|
||||
|
||||
template <class _Flags, enable_if_t<is_simd_flag_type_v<_Flags>, int> = 0>
|
||||
_LIBCPP_HIDE_FROM_ABI void copy_to(value_type* __mem, _Flags) const {
|
||||
_Impl::__store(__s_, _Flags::template __apply<simd_mask>(__mem));
|
||||
}
|
||||
|
||||
// scalar access [simd.mask.subscr]
|
||||
_LIBCPP_HIDE_FROM_ABI reference operator[](size_t __i) noexcept { return reference(__s_, __i); }
|
||||
_LIBCPP_HIDE_FROM_ABI value_type operator[](size_t __i) const noexcept { return __s_.__get(__i); }
|
||||
};
|
||||
|
||||
template <class _Tp, class _Abi>
|
||||
inline constexpr bool is_simd_mask_v<simd_mask<_Tp, _Abi>> = true;
|
||||
|
||||
template <class _Tp>
|
||||
using native_simd_mask = simd_mask<_Tp, simd_abi::native<_Tp>>;
|
||||
|
||||
template <class _Tp, int _Np>
|
||||
using fixed_size_simd_mask = simd_mask<_Tp, simd_abi::fixed_size<_Np>>;
|
||||
|
||||
} // namespace parallelism_v2
|
||||
_LIBCPP_END_NAMESPACE_EXPERIMENTAL
|
||||
|
||||
#endif // _LIBCPP_STD_VER >= 17 && defined(_LIBCPP_ENABLE_EXPERIMENTAL)
|
||||
#endif // _LIBCPP_EXPERIMENTAL___SIMD_SIMD_MASK_H
|
75
third_party/libcxx/experimental/__simd/traits.h
vendored
Normal file
75
third_party/libcxx/experimental/__simd/traits.h
vendored
Normal file
|
@ -0,0 +1,75 @@
|
|||
// -*- C++ -*-
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef _LIBCPP_EXPERIMENTAL___SIMD_TRAITS_H
|
||||
#define _LIBCPP_EXPERIMENTAL___SIMD_TRAITS_H
|
||||
|
||||
#include <__bit/bit_ceil.h>
|
||||
#include <__type_traits/integral_constant.h>
|
||||
#include <__type_traits/is_same.h>
|
||||
#include <cstddef>
|
||||
#include <experimental/__config>
|
||||
#include <experimental/__simd/declaration.h>
|
||||
#include <experimental/__simd/utility.h>
|
||||
|
||||
#if _LIBCPP_STD_VER >= 17 && defined(_LIBCPP_ENABLE_EXPERIMENTAL)
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL
|
||||
inline namespace parallelism_v2 {
|
||||
|
||||
// traits [simd.traits]
|
||||
template <class _Tp>
|
||||
inline constexpr bool is_abi_tag_v = false;
|
||||
|
||||
template <class _Tp>
|
||||
struct is_abi_tag : bool_constant<is_abi_tag_v<_Tp>> {};
|
||||
|
||||
template <class _Tp>
|
||||
inline constexpr bool is_simd_v = false;
|
||||
|
||||
template <class _Tp>
|
||||
struct is_simd : bool_constant<is_simd_v<_Tp>> {};
|
||||
|
||||
template <class _Tp>
|
||||
inline constexpr bool is_simd_mask_v = false;
|
||||
|
||||
template <class _Tp>
|
||||
struct is_simd_mask : bool_constant<is_simd_mask_v<_Tp>> {};
|
||||
|
||||
template <class _Tp>
|
||||
inline constexpr bool is_simd_flag_type_v = false;
|
||||
|
||||
template <class _Tp>
|
||||
struct is_simd_flag_type : bool_constant<is_simd_flag_type_v<_Tp>> {};
|
||||
|
||||
template <class _Tp, class _Abi = simd_abi::compatible<_Tp>, bool = (__is_vectorizable_v<_Tp> && is_abi_tag_v<_Abi>)>
|
||||
struct simd_size : integral_constant<size_t, _Abi::__simd_size> {};
|
||||
|
||||
template <class _Tp, class _Abi>
|
||||
struct simd_size<_Tp, _Abi, false> {};
|
||||
|
||||
template <class _Tp, class _Abi = simd_abi::compatible<_Tp>>
|
||||
inline constexpr size_t simd_size_v = simd_size<_Tp, _Abi>::value;
|
||||
|
||||
template <class _Tp,
|
||||
class _Up = typename _Tp::value_type,
|
||||
bool = (is_simd_v<_Tp> && __is_vectorizable_v<_Up>) || (is_simd_mask_v<_Tp> && is_same_v<_Up, bool>)>
|
||||
struct memory_alignment : integral_constant<size_t, std::__bit_ceil(sizeof(_Up) * _Tp::size())> {};
|
||||
|
||||
template <class _Tp, class _Up>
|
||||
struct memory_alignment<_Tp, _Up, false> {};
|
||||
|
||||
template <class _Tp, class _Up = typename _Tp::value_type>
|
||||
inline constexpr size_t memory_alignment_v = memory_alignment<_Tp, _Up>::value;
|
||||
|
||||
} // namespace parallelism_v2
|
||||
_LIBCPP_END_NAMESPACE_EXPERIMENTAL
|
||||
|
||||
#endif // _LIBCPP_STD_VER >= 17 && defined(_LIBCPP_ENABLE_EXPERIMENTAL)
|
||||
#endif // _LIBCPP_EXPERIMENTAL___SIMD_TRAITS_H
|
103
third_party/libcxx/experimental/__simd/utility.h
vendored
Normal file
103
third_party/libcxx/experimental/__simd/utility.h
vendored
Normal file
|
@ -0,0 +1,103 @@
|
|||
// -*- C++ -*-
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef _LIBCPP_EXPERIMENTAL___SIMD_UTILITY_H
|
||||
#define _LIBCPP_EXPERIMENTAL___SIMD_UTILITY_H
|
||||
|
||||
#include <__type_traits/is_arithmetic.h>
|
||||
#include <__type_traits/is_const.h>
|
||||
#include <__type_traits/is_constant_evaluated.h>
|
||||
#include <__type_traits/is_convertible.h>
|
||||
#include <__type_traits/is_same.h>
|
||||
#include <__type_traits/is_unsigned.h>
|
||||
#include <__type_traits/is_volatile.h>
|
||||
#include <__type_traits/void_t.h>
|
||||
#include <__utility/declval.h>
|
||||
#include <__utility/integer_sequence.h>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <experimental/__config>
|
||||
#include <limits>
|
||||
|
||||
_LIBCPP_PUSH_MACROS
|
||||
#include <__undef_macros>
|
||||
|
||||
#if _LIBCPP_STD_VER >= 17 && defined(_LIBCPP_ENABLE_EXPERIMENTAL)
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL
|
||||
inline namespace parallelism_v2 {
|
||||
template <class _Tp>
|
||||
inline constexpr bool __is_vectorizable_v =
|
||||
is_arithmetic_v<_Tp> && !is_const_v<_Tp> && !is_volatile_v<_Tp> && !is_same_v<_Tp, bool>;
|
||||
|
||||
template <class _Tp>
|
||||
_LIBCPP_HIDE_FROM_ABI auto __choose_mask_type() {
|
||||
if constexpr (sizeof(_Tp) == 1) {
|
||||
return uint8_t{};
|
||||
} else if constexpr (sizeof(_Tp) == 2) {
|
||||
return uint16_t{};
|
||||
} else if constexpr (sizeof(_Tp) == 4) {
|
||||
return uint32_t{};
|
||||
} else if constexpr (sizeof(_Tp) == 8) {
|
||||
return uint64_t{};
|
||||
}
|
||||
# ifndef _LIBCPP_HAS_NO_INT128
|
||||
else if constexpr (sizeof(_Tp) == 16) {
|
||||
return __uint128_t{};
|
||||
}
|
||||
# endif
|
||||
else
|
||||
static_assert(sizeof(_Tp) == 0, "Unexpected size");
|
||||
}
|
||||
|
||||
template <class _Tp>
|
||||
_LIBCPP_HIDE_FROM_ABI auto constexpr __set_all_bits(bool __v) {
|
||||
return __v ? (numeric_limits<decltype(__choose_mask_type<_Tp>())>::max()) : 0;
|
||||
}
|
||||
|
||||
template <class _From, class _To, class = void>
|
||||
inline constexpr bool __is_non_narrowing_convertible_v = false;
|
||||
|
||||
template <class _From, class _To>
|
||||
inline constexpr bool __is_non_narrowing_convertible_v<_From, _To, std::void_t<decltype(_To{std::declval<_From>()})>> =
|
||||
true;
|
||||
|
||||
template <class _Tp, class _Up>
|
||||
inline constexpr bool __can_broadcast_v =
|
||||
(__is_vectorizable_v<_Up> && __is_non_narrowing_convertible_v<_Up, _Tp>) ||
|
||||
(!__is_vectorizable_v<_Up> && is_convertible_v<_Up, _Tp>) || is_same_v<_Up, int> ||
|
||||
(is_same_v<_Up, unsigned int> && is_unsigned_v<_Tp>);
|
||||
|
||||
template <class _Tp, class _Generator, std::size_t _Idx, class = void>
|
||||
inline constexpr bool __is_well_formed = false;
|
||||
|
||||
template <class _Tp, class _Generator, std::size_t _Idx>
|
||||
inline constexpr bool
|
||||
__is_well_formed<_Tp,
|
||||
_Generator,
|
||||
_Idx,
|
||||
std::void_t<decltype(std::declval<_Generator>()(integral_constant<size_t, _Idx>()))>> =
|
||||
__can_broadcast_v<_Tp, decltype(std::declval<_Generator>()(integral_constant<size_t, _Idx>()))>;
|
||||
|
||||
template <class _Tp, class _Generator, std::size_t... _Idxes>
|
||||
_LIBCPP_HIDE_FROM_ABI constexpr bool __can_generate(index_sequence<_Idxes...>) {
|
||||
return (true && ... && __is_well_formed<_Tp, _Generator, _Idxes>);
|
||||
}
|
||||
|
||||
template <class _Tp, class _Generator, std::size_t _Size>
|
||||
inline constexpr bool __can_generate_v = experimental::__can_generate<_Tp, _Generator>(make_index_sequence<_Size>());
|
||||
|
||||
} // namespace parallelism_v2
|
||||
_LIBCPP_END_NAMESPACE_EXPERIMENTAL
|
||||
|
||||
#endif // _LIBCPP_STD_VER >= 17 && defined(_LIBCPP_ENABLE_EXPERIMENTAL)
|
||||
|
||||
_LIBCPP_POP_MACROS
|
||||
|
||||
#endif // _LIBCPP_EXPERIMENTAL___SIMD_UTILITY_H
|
119
third_party/libcxx/experimental/__simd/vec_ext.h
vendored
Normal file
119
third_party/libcxx/experimental/__simd/vec_ext.h
vendored
Normal file
|
@ -0,0 +1,119 @@
|
|||
// -*- C++ -*-
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef _LIBCPP_EXPERIMENTAL___SIMD_VEC_EXT_H
|
||||
#define _LIBCPP_EXPERIMENTAL___SIMD_VEC_EXT_H
|
||||
|
||||
#include <__assert>
|
||||
#include <__bit/bit_ceil.h>
|
||||
#include <__utility/forward.h>
|
||||
#include <__utility/integer_sequence.h>
|
||||
#include <cstddef>
|
||||
#include <experimental/__config>
|
||||
#include <experimental/__simd/declaration.h>
|
||||
#include <experimental/__simd/traits.h>
|
||||
#include <experimental/__simd/utility.h>
|
||||
|
||||
#if _LIBCPP_STD_VER >= 17 && defined(_LIBCPP_ENABLE_EXPERIMENTAL)
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL
|
||||
inline namespace parallelism_v2 {
|
||||
namespace simd_abi {
|
||||
template <int _Np>
|
||||
struct __vec_ext {
|
||||
static constexpr size_t __simd_size = _Np;
|
||||
};
|
||||
} // namespace simd_abi
|
||||
|
||||
template <int _Np>
|
||||
inline constexpr bool is_abi_tag_v<simd_abi::__vec_ext<_Np>> = _Np > 0 && _Np <= 32;
|
||||
|
||||
template <class _Tp, int _Np>
|
||||
struct __simd_storage<_Tp, simd_abi::__vec_ext<_Np>> {
|
||||
_Tp __data __attribute__((__vector_size__(std::__bit_ceil((sizeof(_Tp) * _Np)))));
|
||||
|
||||
_LIBCPP_HIDE_FROM_ABI _Tp __get(size_t __idx) const noexcept {
|
||||
_LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(__idx >= 0 && __idx < _Np, "Index is out of bounds");
|
||||
return __data[__idx];
|
||||
}
|
||||
_LIBCPP_HIDE_FROM_ABI void __set(size_t __idx, _Tp __v) noexcept {
|
||||
_LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(__idx >= 0 && __idx < _Np, "Index is out of bounds");
|
||||
__data[__idx] = __v;
|
||||
}
|
||||
};
|
||||
|
||||
template <class _Tp, int _Np>
|
||||
struct __mask_storage<_Tp, simd_abi::__vec_ext<_Np>>
|
||||
: __simd_storage<decltype(experimental::__choose_mask_type<_Tp>()), simd_abi::__vec_ext<_Np>> {};
|
||||
|
||||
template <class _Tp, int _Np>
|
||||
struct __simd_operations<_Tp, simd_abi::__vec_ext<_Np>> {
|
||||
using _SimdStorage = __simd_storage<_Tp, simd_abi::__vec_ext<_Np>>;
|
||||
using _MaskStorage = __mask_storage<_Tp, simd_abi::__vec_ext<_Np>>;
|
||||
|
||||
static _LIBCPP_HIDE_FROM_ABI _SimdStorage __broadcast(_Tp __v) noexcept {
|
||||
_SimdStorage __result;
|
||||
for (int __i = 0; __i < _Np; ++__i) {
|
||||
__result.__set(__i, __v);
|
||||
}
|
||||
return __result;
|
||||
}
|
||||
|
||||
template <class _Generator, size_t... _Is>
|
||||
static _LIBCPP_HIDE_FROM_ABI _SimdStorage __generate_init(_Generator&& __g, std::index_sequence<_Is...>) {
|
||||
return _SimdStorage{{__g(std::integral_constant<size_t, _Is>())...}};
|
||||
}
|
||||
|
||||
template <class _Generator>
|
||||
static _LIBCPP_HIDE_FROM_ABI _SimdStorage __generate(_Generator&& __g) noexcept {
|
||||
return __generate_init(std::forward<_Generator>(__g), std::make_index_sequence<_Np>());
|
||||
}
|
||||
|
||||
template <class _Up>
|
||||
static _LIBCPP_HIDE_FROM_ABI void __load(_SimdStorage& __s, const _Up* __mem) noexcept {
|
||||
for (size_t __i = 0; __i < _Np; __i++)
|
||||
__s.__data[__i] = static_cast<_Tp>(__mem[__i]);
|
||||
}
|
||||
|
||||
template <class _Up>
|
||||
static _LIBCPP_HIDE_FROM_ABI void __store(_SimdStorage __s, _Up* __mem) noexcept {
|
||||
for (size_t __i = 0; __i < _Np; __i++)
|
||||
__mem[__i] = static_cast<_Up>(__s.__data[__i]);
|
||||
}
|
||||
};
|
||||
|
||||
template <class _Tp, int _Np>
|
||||
struct __mask_operations<_Tp, simd_abi::__vec_ext<_Np>> {
|
||||
using _MaskStorage = __mask_storage<_Tp, simd_abi::__vec_ext<_Np>>;
|
||||
|
||||
static _LIBCPP_HIDE_FROM_ABI _MaskStorage __broadcast(bool __v) noexcept {
|
||||
_MaskStorage __result;
|
||||
auto __all_bits_v = experimental::__set_all_bits<_Tp>(__v);
|
||||
for (int __i = 0; __i < _Np; ++__i) {
|
||||
__result.__set(__i, __all_bits_v);
|
||||
}
|
||||
return __result;
|
||||
}
|
||||
|
||||
static _LIBCPP_HIDE_FROM_ABI void __load(_MaskStorage& __s, const bool* __mem) noexcept {
|
||||
for (size_t __i = 0; __i < _Np; __i++)
|
||||
__s.__data[__i] = experimental::__set_all_bits<_Tp>(__mem[__i]);
|
||||
}
|
||||
|
||||
static _LIBCPP_HIDE_FROM_ABI void __store(_MaskStorage __s, bool* __mem) noexcept {
|
||||
for (size_t __i = 0; __i < _Np; __i++)
|
||||
__mem[__i] = static_cast<bool>(__s.__data[__i]);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace parallelism_v2
|
||||
_LIBCPP_END_NAMESPACE_EXPERIMENTAL
|
||||
|
||||
#endif // _LIBCPP_STD_VER >= 17 && defined(_LIBCPP_ENABLE_EXPERIMENTAL)
|
||||
#endif // _LIBCPP_EXPERIMENTAL___SIMD_VEC_EXT_H
|
Loading…
Add table
Add a link
Reference in a new issue