Skip to content

[libc++][NFC] Refactor <experimental/simd> a bit to simplify dependencies #76283

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions libcxx/include/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -914,10 +914,8 @@ set(files
expected
experimental/__config
experimental/__memory
experimental/__simd/abi_tag.h
experimental/__simd/aligned_tag.h
experimental/__simd/declaration.h
experimental/__simd/internal_declaration.h
experimental/__simd/reference.h
experimental/__simd/scalar.h
experimental/__simd/simd.h
Expand Down
55 changes: 0 additions & 55 deletions libcxx/include/experimental/__simd/abi_tag.h

This file was deleted.

13 changes: 11 additions & 2 deletions libcxx/include/experimental/__simd/aligned_tag.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
#ifndef _LIBCPP_EXPERIMENTAL___SIMD_ALIGNED_TAG_H
#define _LIBCPP_EXPERIMENTAL___SIMD_ALIGNED_TAG_H

#include <__bit/bit_ceil.h>
#include <__memory/assume_aligned.h>
#include <cstddef>
#include <experimental/__config>
#include <experimental/__simd/traits.h>

#if _LIBCPP_STD_VER >= 17 && defined(_LIBCPP_ENABLE_EXPERIMENTAL)

Expand All @@ -30,16 +30,22 @@ struct element_aligned_tag {
}
};

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 = std::__bit_ceil(sizeof(_Up) * _Tp::size());
static constexpr size_t __alignment = memory_alignment_v<_Tp, _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>
Expand All @@ -51,6 +57,9 @@ struct overaligned_tag {
}
};

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{};
Expand Down
52 changes: 51 additions & 1 deletion libcxx/include/experimental/__simd/declaration.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,63 @@
#ifndef _LIBCPP_EXPERIMENTAL___SIMD_DECLARATION_H
#define _LIBCPP_EXPERIMENTAL___SIMD_DECLARATION_H

#include <cstddef>
#include <experimental/__config>
#include <experimental/__simd/abi_tag.h>

#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;
Expand Down
41 changes: 0 additions & 41 deletions libcxx/include/experimental/__simd/internal_declaration.h

This file was deleted.

2 changes: 1 addition & 1 deletion libcxx/include/experimental/__simd/scalar.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

#include <cstddef>
#include <experimental/__config>
#include <experimental/__simd/internal_declaration.h>
#include <experimental/__simd/declaration.h>
#include <experimental/__simd/traits.h>

#if _LIBCPP_STD_VER >= 17 && defined(_LIBCPP_ENABLE_EXPERIMENTAL)
Expand Down
2 changes: 0 additions & 2 deletions libcxx/include/experimental/__simd/simd.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@
#include <__utility/forward.h>
#include <cstddef>
#include <experimental/__config>
#include <experimental/__simd/abi_tag.h>
#include <experimental/__simd/declaration.h>
#include <experimental/__simd/internal_declaration.h>
#include <experimental/__simd/reference.h>
#include <experimental/__simd/traits.h>
#include <experimental/__simd/utility.h>
Expand Down
2 changes: 0 additions & 2 deletions libcxx/include/experimental/__simd/simd_mask.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@
#include <__type_traits/is_same.h>
#include <cstddef>
#include <experimental/__config>
#include <experimental/__simd/abi_tag.h>
#include <experimental/__simd/declaration.h>
#include <experimental/__simd/internal_declaration.h>
#include <experimental/__simd/reference.h>
#include <experimental/__simd/traits.h>

Expand Down
15 changes: 2 additions & 13 deletions libcxx/include/experimental/__simd/traits.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,12 @@
#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/abi_tag.h>
#include <experimental/__simd/aligned_tag.h>
#include <experimental/__simd/declaration.h>
#include <experimental/__simd/internal_declaration.h>
#include <experimental/__simd/utility.h>

#if _LIBCPP_STD_VER >= 17 && defined(_LIBCPP_ENABLE_EXPERIMENTAL)
Expand Down Expand Up @@ -47,15 +45,6 @@ struct is_simd_mask : bool_constant<is_simd_mask_v<_Tp>> {};
template <class _Tp>
inline constexpr bool is_simd_flag_type_v = false;

template <>
inline constexpr bool is_simd_flag_type_v<element_aligned_tag> = true;

template <>
inline constexpr bool is_simd_flag_type_v<vector_aligned_tag> = true;

template <size_t _Np>
inline constexpr bool is_simd_flag_type_v<overaligned_tag<_Np>> = true;

template <class _Tp>
struct is_simd_flag_type : bool_constant<is_simd_flag_type_v<_Tp>> {};

Expand All @@ -71,7 +60,7 @@ 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, vector_aligned_tag::__alignment<_Tp, _Up>> {};
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> {};
Expand Down
2 changes: 1 addition & 1 deletion libcxx/include/experimental/__simd/vec_ext.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include <__utility/integer_sequence.h>
#include <cstddef>
#include <experimental/__config>
#include <experimental/__simd/internal_declaration.h>
#include <experimental/__simd/declaration.h>
#include <experimental/__simd/traits.h>
#include <experimental/__simd/utility.h>

Expand Down
1 change: 0 additions & 1 deletion libcxx/include/experimental/simd
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ inline namespace parallelism_v2 {
#endif

#include <experimental/__config>
#include <experimental/__simd/abi_tag.h>
#include <experimental/__simd/aligned_tag.h>
#include <experimental/__simd/declaration.h>
#include <experimental/__simd/scalar.h>
Expand Down
2 changes: 0 additions & 2 deletions libcxx/include/module.modulemap.in
Original file line number Diff line number Diff line change
Expand Up @@ -530,10 +530,8 @@ module std_experimental [system] {
export *
}
module simd {
module abi_tag { private header "experimental/__simd/abi_tag.h" }
module aligned_tag { private header "experimental/__simd/aligned_tag.h" }
module declaration { private header "experimental/__simd/declaration.h" }
module internal_declaration { private header "experimental/__simd/internal_declaration.h" }
module reference { private header "experimental/__simd/reference.h" }
module scalar { private header "experimental/__simd/scalar.h" }
module simd { private header "experimental/__simd/simd.h" }
Expand Down