• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
10 #ifndef _LIBCPP_EXPERIMENTAL___SIMD_TRAITS_H
11 #define _LIBCPP_EXPERIMENTAL___SIMD_TRAITS_H
12 
13 #include <__type_traits/integral_constant.h>
14 #include <__type_traits/is_same.h>
15 #include <cstddef>
16 #include <experimental/__config>
17 #include <experimental/__simd/abi_tag.h>
18 #include <experimental/__simd/aligned_tag.h>
19 #include <experimental/__simd/declaration.h>
20 #include <experimental/__simd/internal_declaration.h>
21 #include <experimental/__simd/utility.h>
22 
23 #if _LIBCPP_STD_VER >= 17 && defined(_LIBCPP_ENABLE_EXPERIMENTAL)
24 
25 _LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL
26 inline namespace parallelism_v2 {
27 
28 // traits [simd.traits]
29 template <class _Tp>
30 inline constexpr bool is_abi_tag_v = false;
31 
32 template <class _Tp>
33 struct is_abi_tag : bool_constant<is_abi_tag_v<_Tp>> {};
34 
35 template <class _Tp>
36 inline constexpr bool is_simd_v = false;
37 
38 template <class _Tp>
39 struct is_simd : bool_constant<is_simd_v<_Tp>> {};
40 
41 template <class _Tp>
42 inline constexpr bool is_simd_mask_v = false;
43 
44 template <class _Tp>
45 struct is_simd_mask : bool_constant<is_simd_mask_v<_Tp>> {};
46 
47 template <class _Tp>
48 inline constexpr bool is_simd_flag_type_v = false;
49 
50 template <>
51 inline constexpr bool is_simd_flag_type_v<element_aligned_tag> = true;
52 
53 template <>
54 inline constexpr bool is_simd_flag_type_v<vector_aligned_tag> = true;
55 
56 template <size_t _Np>
57 inline constexpr bool is_simd_flag_type_v<overaligned_tag<_Np>> = true;
58 
59 template <class _Tp>
60 struct is_simd_flag_type : bool_constant<is_simd_flag_type_v<_Tp>> {};
61 
62 template <class _Tp, class _Abi = simd_abi::compatible<_Tp>, bool = (__is_vectorizable_v<_Tp> && is_abi_tag_v<_Abi>)>
63 struct simd_size : integral_constant<size_t, _Abi::__simd_size> {};
64 
65 template <class _Tp, class _Abi>
66 struct simd_size<_Tp, _Abi, false> {};
67 
68 template <class _Tp, class _Abi = simd_abi::compatible<_Tp>>
69 inline constexpr size_t simd_size_v = simd_size<_Tp, _Abi>::value;
70 
71 template <class _Tp,
72           class _Up = typename _Tp::value_type,
73           bool      = (is_simd_v<_Tp> && __is_vectorizable_v<_Up>) || (is_simd_mask_v<_Tp> && is_same_v<_Up, bool>)>
74 struct memory_alignment : integral_constant<size_t, vector_aligned_tag::__alignment<_Tp, _Up>> {};
75 
76 template <class _Tp, class _Up>
77 struct memory_alignment<_Tp, _Up, false> {};
78 
79 template <class _Tp, class _Up = typename _Tp::value_type>
80 inline constexpr size_t memory_alignment_v = memory_alignment<_Tp, _Up>::value;
81 
82 } // namespace parallelism_v2
83 _LIBCPP_END_NAMESPACE_EXPERIMENTAL
84 
85 #endif // _LIBCPP_STD_VER >= 17 && defined(_LIBCPP_ENABLE_EXPERIMENTAL)
86 #endif // _LIBCPP_EXPERIMENTAL___SIMD_TRAITS_H
87