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

This commit is contained in:
Nikolas Klauser 2023-12-24 08:50:01 +01:00 committed by GitHub
parent eeeb963841
commit 50ae0da058
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 66 additions and 123 deletions

View File

@ -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

View File

@ -1,55 +0,0 @@
// -*- 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_ABI_TAG_H
#define _LIBCPP_EXPERIMENTAL___SIMD_ABI_TAG_H
#include <cstddef>
#include <experimental/__config>
#include <experimental/__simd/internal_declaration.h>
#if _LIBCPP_STD_VER >= 17 && defined(_LIBCPP_ENABLE_EXPERIMENTAL)
_LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL
inline namespace parallelism_v2 {
namespace simd_abi {
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
} // namespace parallelism_v2
_LIBCPP_END_NAMESPACE_EXPERIMENTAL
#endif // _LIBCPP_STD_VER >= 17 && defined(_LIBCPP_ENABLE_EXPERIMENTAL)
#endif // _LIBCPP_EXPERIMENTAL___SIMD_ABI_TAG_H

View File

@ -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)
@ -30,9 +30,12 @@ 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) {
@ -40,6 +43,9 @@ struct vector_aligned_tag {
}
};
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>
@ -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{};

View File

@ -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;

View File

@ -1,41 +0,0 @@
// -*- 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_INTERNAL_DECLARATION_H
#define _LIBCPP_EXPERIMENTAL___SIMD_INTERNAL_DECLARATION_H
#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;
} // 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;
} // namespace parallelism_v2
_LIBCPP_END_NAMESPACE_EXPERIMENTAL
#endif // _LIBCPP_STD_VER >= 17 && defined(_LIBCPP_ENABLE_EXPERIMENTAL)
#endif // _LIBCPP_EXPERIMENTAL___SIMD_INTERNAL_DECLARATION_H

View File

@ -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)

View File

@ -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>

View File

@ -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>

View File

@ -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)
@ -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>> {};
@ -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> {};

View File

@ -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>

View File

@ -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>

View File

@ -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" }