Path: blob/main/contrib/llvm-project/libcxx/include/__memory/assume_aligned.h
35233 views
// -*- C++ -*-1//===----------------------------------------------------------------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//89#ifndef _LIBCPP___MEMORY_ASSUME_ALIGNED_H10#define _LIBCPP___MEMORY_ASSUME_ALIGNED_H1112#include <__assert>13#include <__config>14#include <__type_traits/is_constant_evaluated.h>15#include <cstddef>16#include <cstdint>1718#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)19# pragma GCC system_header20#endif2122_LIBCPP_BEGIN_NAMESPACE_STD2324template <size_t _Np, class _Tp>25_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Tp* __assume_aligned(_Tp* __ptr) {26static_assert(_Np != 0 && (_Np & (_Np - 1)) == 0, "std::assume_aligned<N>(p) requires N to be a power of two");2728if (__libcpp_is_constant_evaluated()) {29(void)__builtin_assume_aligned(__ptr, _Np);30return __ptr;31} else {32_LIBCPP_ASSERT_ARGUMENT_WITHIN_DOMAIN(33reinterpret_cast<uintptr_t>(__ptr) % _Np == 0, "Alignment assumption is violated");34return static_cast<_Tp*>(__builtin_assume_aligned(__ptr, _Np));35}36}3738#if _LIBCPP_STD_VER >= 203940template <size_t _Np, class _Tp>41[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _Tp* assume_aligned(_Tp* __ptr) {42return std::__assume_aligned<_Np>(__ptr);43}4445#endif // _LIBCPP_STD_VER >= 204647_LIBCPP_END_NAMESPACE_STD4849#endif // _LIBCPP___MEMORY_ASSUME_ALIGNED_H505152