File indexing completed on 2026-05-03 08:13:56
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #ifndef _LIBCPP___MEMORY_ASSUME_ALIGNED_H
0011 #define _LIBCPP___MEMORY_ASSUME_ALIGNED_H
0012
0013 #include <__assert>
0014 #include <__config>
0015 #include <__cstddef/size_t.h>
0016 #include <__type_traits/is_constant_evaluated.h>
0017 #include <cstdint>
0018
0019 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
0020 # pragma GCC system_header
0021 #endif
0022
0023 _LIBCPP_BEGIN_NAMESPACE_STD
0024
0025 template <size_t _Np, class _Tp>
0026 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Tp* __assume_aligned(_Tp* __ptr) {
0027 static_assert(_Np != 0 && (_Np & (_Np - 1)) == 0, "std::assume_aligned<N>(p) requires N to be a power of two");
0028
0029 if (__libcpp_is_constant_evaluated()) {
0030 (void)__builtin_assume_aligned(__ptr, _Np);
0031 return __ptr;
0032 } else {
0033 _LIBCPP_ASSERT_ARGUMENT_WITHIN_DOMAIN(
0034 reinterpret_cast<uintptr_t>(__ptr) % _Np == 0, "Alignment assumption is violated");
0035 return static_cast<_Tp*>(__builtin_assume_aligned(__ptr, _Np));
0036 }
0037 }
0038
0039 #if _LIBCPP_STD_VER >= 20
0040
0041 template <size_t _Np, class _Tp>
0042 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _Tp* assume_aligned(_Tp* __ptr) {
0043 return std::__assume_aligned<_Np>(__ptr);
0044 }
0045
0046 #endif
0047
0048 _LIBCPP_END_NAMESPACE_STD
0049
0050 #endif