Warning: This file is not a C or C++ file. It does not have highlighting.

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 <__config>
14#include <__cstddef/size_t.h>
15#include <__memory/assume_aligned.h>
16#include <__type_traits/remove_const.h>
17#include <experimental/__simd/traits.h>
18
19#if _LIBCPP_STD_VER >= 17 && defined(_LIBCPP_ENABLE_EXPERIMENTAL)
20
21_LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL
22inline namespace parallelism_v2 {
23// memory alignment
24struct 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>
29 static _LIBCPP_HIDE_FROM_ABI constexpr _Up* __apply(_Up* __ptr) {
30 return __ptr;
31 }
32};
33
34template <>
35inline constexpr bool is_simd_flag_type_v<element_aligned_tag> = true;
36
37struct 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>
42 static _LIBCPP_HIDE_FROM_ABI constexpr _Up* __apply(_Up* __ptr) {
43 return std::__assume_aligned<__alignment<_Tp, _Up>, _Up>(__ptr);
44 }
45};
46
47template <>
48inline constexpr bool is_simd_flag_type_v<vector_aligned_tag> = true;
49
50template <size_t _Np>
51struct 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>
56 static _LIBCPP_HIDE_FROM_ABI constexpr _Up* __apply(_Up* __ptr) {
57 return std::__assume_aligned<__alignment<_Tp, _Up>, _Up>(__ptr);
58 }
59};
60
61template <size_t _Np>
62inline constexpr bool is_simd_flag_type_v<overaligned_tag<_Np>> = true;
63
64inline constexpr element_aligned_tag element_aligned{};
65
66inline constexpr vector_aligned_tag vector_aligned{};
67
68template <size_t _Np>
69inline 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

Warning: This file is not a C or C++ file. It does not have highlighting.

source code of libcxx/include/experimental/__simd/aligned_tag.h