• 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_ALIGNED_TAG_H
11 #define _LIBCPP_EXPERIMENTAL___SIMD_ALIGNED_TAG_H
12 
13 #include <__bit/bit_ceil.h>
14 #include <__memory/assume_aligned.h>
15 #include <cstddef>
16 #include <experimental/__config>
17 
18 #if _LIBCPP_STD_VER >= 17 && defined(_LIBCPP_ENABLE_EXPERIMENTAL)
19 
20 _LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL
21 inline namespace parallelism_v2 {
22 // memory alignment
23 struct element_aligned_tag {
24   template <class _Tp, class _Up = typename _Tp::value_type>
25   static constexpr size_t __alignment = alignof(_Up);
26 
27   template <class _Tp, class _Up>
__applyelement_aligned_tag28   static _LIBCPP_HIDE_FROM_ABI constexpr _Up* __apply(_Up* __ptr) {
29     return __ptr;
30   }
31 };
32 
33 struct vector_aligned_tag {
34   template <class _Tp, class _Up = typename _Tp::value_type>
35   static constexpr size_t __alignment = std::__bit_ceil(sizeof(_Up) * _Tp::size());
36 
37   template <class _Tp, class _Up>
__applyvector_aligned_tag38   static _LIBCPP_HIDE_FROM_ABI constexpr _Up* __apply(_Up* __ptr) {
39     return std::__assume_aligned<__alignment<_Tp, _Up>, _Up>(__ptr);
40   }
41 };
42 
43 template <size_t _Np>
44 struct overaligned_tag {
45   template <class _Tp, class _Up = typename _Tp::value_type>
46   static constexpr size_t __alignment = _Np;
47 
48   template <class _Tp, class _Up>
__applyoveraligned_tag49   static _LIBCPP_HIDE_FROM_ABI constexpr _Up* __apply(_Up* __ptr) {
50     return std::__assume_aligned<__alignment<_Tp, _Up>, _Up>(__ptr);
51   }
52 };
53 
54 inline constexpr element_aligned_tag element_aligned{};
55 
56 inline constexpr vector_aligned_tag vector_aligned{};
57 
58 template <size_t _Np>
59 inline constexpr overaligned_tag<_Np> overaligned{};
60 
61 } // namespace parallelism_v2
62 _LIBCPP_END_NAMESPACE_EXPERIMENTAL
63 
64 #endif // _LIBCPP_STD_VER >= 17 && defined(_LIBCPP_ENABLE_EXPERIMENTAL)
65 #endif // _LIBCPP_EXPERIMENTAL___SIMD_ALIGNED_TAG_H
66