traits.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. // -*- C++ -*-
  2. //===----------------------------------------------------------------------===//
  3. //
  4. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  5. // See https://llvm.org/LICENSE.txt for license information.
  6. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  7. //
  8. //===----------------------------------------------------------------------===//
  9. #ifndef _LIBCPP_EXPERIMENTAL___SIMD_TRAITS_H
  10. #define _LIBCPP_EXPERIMENTAL___SIMD_TRAITS_H
  11. #include <experimental/__simd/abi_tag.h>
  12. #include <experimental/__simd/aligned_tag.h>
  13. #include <experimental/__simd/declaration.h>
  14. #include <experimental/__simd/utility.h>
  15. #if _LIBCPP_STD_VER >= 17 && defined(_LIBCPP_ENABLE_EXPERIMENTAL)
  16. _LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL
  17. inline namespace parallelism_v2 {
  18. // traits [simd.traits]
  19. template <class _Tp>
  20. inline constexpr bool is_abi_tag_v = false;
  21. template <>
  22. inline constexpr bool is_abi_tag_v<simd_abi::__scalar> = true;
  23. template <int _Np>
  24. inline constexpr bool is_abi_tag_v<simd_abi::__vec_ext<_Np>> = _Np > 0 && _Np <= 32;
  25. template <class _Tp>
  26. struct is_abi_tag : bool_constant<is_abi_tag_v<_Tp>> {};
  27. template <class _Tp>
  28. inline constexpr bool is_simd_v = false;
  29. template <class _Tp, class _Abi>
  30. inline constexpr bool is_simd_v<simd<_Tp, _Abi>> = true;
  31. template <class _Tp>
  32. struct is_simd : bool_constant<is_simd_v<_Tp>> {};
  33. template <class _Tp>
  34. inline constexpr bool is_simd_mask_v = false;
  35. template <class _Tp, class _Abi>
  36. inline constexpr bool is_simd_mask_v<simd_mask<_Tp, _Abi>> = true;
  37. template <class _Tp>
  38. struct is_simd_mask : bool_constant<is_simd_mask_v<_Tp>> {};
  39. template <class _Tp>
  40. inline constexpr bool is_simd_flag_type_v = false;
  41. template <>
  42. inline constexpr bool is_simd_flag_type_v<element_aligned_tag> = true;
  43. template <>
  44. inline constexpr bool is_simd_flag_type_v<vector_aligned_tag> = true;
  45. template <size_t _Np>
  46. inline constexpr bool is_simd_flag_type_v<overaligned_tag<_Np>> = true;
  47. template <class _Tp>
  48. struct is_simd_flag_type : bool_constant<is_simd_flag_type_v<_Tp>> {};
  49. template <class _Tp, class _Abi = simd_abi::compatible<_Tp>, bool = (__is_vectorizable_v<_Tp> && is_abi_tag_v<_Abi>)>
  50. struct simd_size : integral_constant<size_t, _Abi::__simd_size> {};
  51. template <class _Tp, class _Abi>
  52. struct simd_size<_Tp, _Abi, false> {};
  53. template <class _Tp, class _Abi = simd_abi::compatible<_Tp>>
  54. inline constexpr size_t simd_size_v = simd_size<_Tp, _Abi>::value;
  55. template <class _Tp,
  56. class _Up = typename _Tp::value_type,
  57. bool = (is_simd_v<_Tp> && __is_vectorizable_v<_Up>) || (is_simd_mask_v<_Tp> && is_same_v<_Up, bool>)>
  58. struct memory_alignment : integral_constant<size_t, vector_aligned_tag::__alignment<_Tp, _Up>> {};
  59. template <class _Tp, class _Up>
  60. struct memory_alignment<_Tp, _Up, false> {};
  61. template <class _Tp, class _Up = typename _Tp::value_type>
  62. inline constexpr size_t memory_alignment_v = memory_alignment<_Tp, _Up>::value;
  63. } // namespace parallelism_v2
  64. _LIBCPP_END_NAMESPACE_EXPERIMENTAL
  65. #endif // _LIBCPP_STD_VER >= 17 && defined(_LIBCPP_ENABLE_EXPERIMENTAL)
  66. #endif // _LIBCPP_EXPERIMENTAL___SIMD_TRAITS_H