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_FLOOR_H 10bdd1243dSDimitry Andric #define _LIBCPP___BIT_BIT_FLOOR_H 11bdd1243dSDimitry Andric 12bdd1243dSDimitry Andric #include <__bit/bit_log2.h> 13bdd1243dSDimitry Andric #include <__concepts/arithmetic.h> 14bdd1243dSDimitry Andric #include <__config> 15bdd1243dSDimitry Andric #include <limits> 16bdd1243dSDimitry Andric 17bdd1243dSDimitry Andric #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 18bdd1243dSDimitry Andric # pragma GCC system_header 19bdd1243dSDimitry Andric #endif 20bdd1243dSDimitry Andric 21bdd1243dSDimitry Andric _LIBCPP_BEGIN_NAMESPACE_STD 22bdd1243dSDimitry Andric 23bdd1243dSDimitry Andric #if _LIBCPP_STD_VER >= 20 24bdd1243dSDimitry Andric 25bdd1243dSDimitry Andric template <__libcpp_unsigned_integer _Tp> 26*0fca6ea1SDimitry Andric [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _Tp bit_floor(_Tp __t) noexcept { 27bdd1243dSDimitry Andric return __t == 0 ? 0 : _Tp{1} << std::__bit_log2(__t); 28bdd1243dSDimitry Andric } 29bdd1243dSDimitry Andric 30bdd1243dSDimitry Andric #endif // _LIBCPP_STD_VER >= 20 31bdd1243dSDimitry Andric 32bdd1243dSDimitry Andric _LIBCPP_END_NAMESPACE_STD 33bdd1243dSDimitry Andric 34bdd1243dSDimitry Andric #endif // _LIBCPP___BIT_BIT_FLOOR_H 35