xref: /freebsd-src/contrib/llvm-project/libcxx/include/experimental/__simd/aligned_tag.h (revision 7a6dacaca14b62ca4b74406814becb87a3fefac0)
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_ALIGNED_TAG_H
11 #define _LIBCPP_EXPERIMENTAL___SIMD_ALIGNED_TAG_H
12 
13 #include <__memory/assume_aligned.h>
14 #include <__type_traits/remove_const.h>
15 #include <cstddef>
16 #include <experimental/__config>
17 #include <experimental/__simd/traits.h>
18 
19 #if _LIBCPP_STD_VER >= 17 && defined(_LIBCPP_ENABLE_EXPERIMENTAL)
20 
21 _LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL
22 inline namespace parallelism_v2 {
23 // memory alignment
24 struct element_aligned_tag {
25   template <class _Tp, class _Up = typename _Tp::value_type>
26   static constexpr size_t __alignment = alignof(_Up);
27 
28   template <class _Tp, class _Up>
__applyelement_aligned_tag29   static _LIBCPP_HIDE_FROM_ABI constexpr _Up* __apply(_Up* __ptr) {
30     return __ptr;
31   }
32 };
33 
34 template <>
35 inline constexpr bool is_simd_flag_type_v<element_aligned_tag> = true;
36 
37 struct vector_aligned_tag {
38   template <class _Tp, class _Up = typename _Tp::value_type>
39   static constexpr size_t __alignment = memory_alignment_v<_Tp, remove_const_t<_Up>>;
40 
41   template <class _Tp, class _Up>
__applyvector_aligned_tag42   static _LIBCPP_HIDE_FROM_ABI constexpr _Up* __apply(_Up* __ptr) {
43     return std::__assume_aligned<__alignment<_Tp, _Up>, _Up>(__ptr);
44   }
45 };
46 
47 template <>
48 inline constexpr bool is_simd_flag_type_v<vector_aligned_tag> = true;
49 
50 template <size_t _Np>
51 struct overaligned_tag {
52   template <class _Tp, class _Up = typename _Tp::value_type>
53   static constexpr size_t __alignment = _Np;
54 
55   template <class _Tp, class _Up>
__applyoveraligned_tag56   static _LIBCPP_HIDE_FROM_ABI constexpr _Up* __apply(_Up* __ptr) {
57     return std::__assume_aligned<__alignment<_Tp, _Up>, _Up>(__ptr);
58   }
59 };
60 
61 template <size_t _Np>
62 inline constexpr bool is_simd_flag_type_v<overaligned_tag<_Np>> = true;
63 
64 inline constexpr element_aligned_tag element_aligned{};
65 
66 inline constexpr vector_aligned_tag vector_aligned{};
67 
68 template <size_t _Np>
69 inline constexpr overaligned_tag<_Np> overaligned{};
70 
71 } // namespace parallelism_v2
72 _LIBCPP_END_NAMESPACE_EXPERIMENTAL
73 
74 #endif // _LIBCPP_STD_VER >= 17 && defined(_LIBCPP_ENABLE_EXPERIMENTAL)
75 #endif // _LIBCPP_EXPERIMENTAL___SIMD_ALIGNED_TAG_H
76