Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-03 08:13:34

0001 // -*- C++ -*-
0002 //===----------------------------------------------------------------------===//
0003 //
0004 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0005 // See https://llvm.org/LICENSE.txt for license information.
0006 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0007 //
0008 //===----------------------------------------------------------------------===//
0009 
0010 #ifndef _LIBCPP___CXX03___MEMORY_ASSUME_ALIGNED_H
0011 #define _LIBCPP___CXX03___MEMORY_ASSUME_ALIGNED_H
0012 
0013 #include <__cxx03/__assert>
0014 #include <__cxx03/__config>
0015 #include <__cxx03/__type_traits/is_constant_evaluated.h>
0016 #include <__cxx03/cstddef>
0017 #include <__cxx03/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 _LIBCPP_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 // _LIBCPP_STD_VER >= 20
0047 
0048 _LIBCPP_END_NAMESPACE_STD
0049 
0050 #endif // _LIBCPP___CXX03___MEMORY_ASSUME_ALIGNED_H