Path: blob/main/contrib/llvm-project/libcxx/include/__bit/bit_ceil.h
35260 views
//===----------------------------------------------------------------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#ifndef _LIBCPP___BIT_BIT_CEIL_H9#define _LIBCPP___BIT_BIT_CEIL_H1011#include <__assert>12#include <__bit/countl.h>13#include <__concepts/arithmetic.h>14#include <__config>15#include <limits>1617#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)18# pragma GCC system_header19#endif2021_LIBCPP_BEGIN_NAMESPACE_STD2223#if _LIBCPP_STD_VER >= 172425template <class _Tp>26[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _Tp __bit_ceil(_Tp __t) noexcept {27if (__t < 2)28return 1;29const unsigned __n = numeric_limits<_Tp>::digits - std::__countl_zero((_Tp)(__t - 1u));30_LIBCPP_ASSERT_ARGUMENT_WITHIN_DOMAIN(__n != numeric_limits<_Tp>::digits, "Bad input to bit_ceil");3132if constexpr (sizeof(_Tp) >= sizeof(unsigned))33return _Tp{1} << __n;34else {35const unsigned __extra = numeric_limits<unsigned>::digits - numeric_limits<_Tp>::digits;36const unsigned __ret_val = 1u << (__n + __extra);37return (_Tp)(__ret_val >> __extra);38}39}4041# if _LIBCPP_STD_VER >= 204243template <__libcpp_unsigned_integer _Tp>44[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _Tp bit_ceil(_Tp __t) noexcept {45return std::__bit_ceil(__t);46}4748# endif // _LIBCPP_STD_VER >= 2049#endif // _LIBCPP_STD_VER >= 175051_LIBCPP_END_NAMESPACE_STD5253#endif // _LIBCPP___BIT_BIT_CEIL_H545556