1bdd1243dSDimitry Andric //===----------------------------------------------------------------------===// 2bdd1243dSDimitry Andric // 3bdd1243dSDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4bdd1243dSDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 5bdd1243dSDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6bdd1243dSDimitry Andric // 7bdd1243dSDimitry Andric //===----------------------------------------------------------------------===// 8bdd1243dSDimitry Andric 9bdd1243dSDimitry Andric #ifndef _LIBCPP___BIT_BIT_WIDTH_H 10bdd1243dSDimitry Andric #define _LIBCPP___BIT_BIT_WIDTH_H 11bdd1243dSDimitry Andric 12bdd1243dSDimitry Andric #include <__bit/bit_log2.h> 13bdd1243dSDimitry Andric #include <__concepts/arithmetic.h> 14bdd1243dSDimitry Andric #include <__config> 15bdd1243dSDimitry Andric 16bdd1243dSDimitry Andric #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 17bdd1243dSDimitry Andric # pragma GCC system_header 18bdd1243dSDimitry Andric #endif 19bdd1243dSDimitry Andric 20bdd1243dSDimitry Andric #if _LIBCPP_STD_VER >= 20 21bdd1243dSDimitry Andric 22bdd1243dSDimitry Andric _LIBCPP_BEGIN_NAMESPACE_STD 23bdd1243dSDimitry Andric 24bdd1243dSDimitry Andric template <__libcpp_unsigned_integer _Tp> bit_width(_Tp __t)25*0fca6ea1SDimitry Andric[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr int bit_width(_Tp __t) noexcept { 26bdd1243dSDimitry Andric return __t == 0 ? 0 : std::__bit_log2(__t) + 1; 27bdd1243dSDimitry Andric } 28bdd1243dSDimitry Andric 29bdd1243dSDimitry Andric _LIBCPP_END_NAMESPACE_STD 30bdd1243dSDimitry Andric 31bdd1243dSDimitry Andric #endif // _LIBCPP_STD_VER >= 20 32bdd1243dSDimitry Andric 33bdd1243dSDimitry Andric #endif // _LIBCPP___BIT_BIT_WIDTH_H 34