diff options
author | mikhnenko <mikhnenko@yandex-team.com> | 2024-03-27 10:35:27 +0300 |
---|---|---|
committer | mikhnenko <mikhnenko@yandex-team.com> | 2024-03-27 10:47:39 +0300 |
commit | 9b902baa4a858f2176c82aa0b20f88232f0da0d8 (patch) | |
tree | 7165a551c2244c4b3c28479ac3a3f6d62346ec89 /contrib/libs/cxxsupp/libcxx/include/__bit | |
parent | a1c989e67e438005fa0c34ed0e910536c8941862 (diff) | |
download | ydb-9b902baa4a858f2176c82aa0b20f88232f0da0d8.tar.gz |
Update libcxx to 10 Oct 2023 dc129d6f715cf83a2072fc8de8b4e4c70bca6935
97ce40d276e44357a49b7a945af841896126dca8
Diffstat (limited to 'contrib/libs/cxxsupp/libcxx/include/__bit')
4 files changed, 65 insertions, 21 deletions
diff --git a/contrib/libs/cxxsupp/libcxx/include/__bit/bit_ceil.h b/contrib/libs/cxxsupp/libcxx/include/__bit/bit_ceil.h index 706d446359..9eae5c391a 100644 --- a/contrib/libs/cxxsupp/libcxx/include/__bit/bit_ceil.h +++ b/contrib/libs/cxxsupp/libcxx/include/__bit/bit_ceil.h @@ -21,13 +21,13 @@ _LIBCPP_BEGIN_NAMESPACE_STD -#if _LIBCPP_STD_VER >= 20 +#if _LIBCPP_STD_VER >= 17 -template <__libcpp_unsigned_integer _Tp> -_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr _Tp bit_ceil(_Tp __t) noexcept { +template <class _Tp> +_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr _Tp __bit_ceil(_Tp __t) noexcept { if (__t < 2) return 1; - const unsigned __n = numeric_limits<_Tp>::digits - std::countl_zero((_Tp)(__t - 1u)); + const unsigned __n = numeric_limits<_Tp>::digits - std::__countl_zero((_Tp)(__t - 1u)); _LIBCPP_ASSERT_UNCATEGORIZED(__n != numeric_limits<_Tp>::digits, "Bad input to bit_ceil"); if constexpr (sizeof(_Tp) >= sizeof(unsigned)) @@ -39,7 +39,15 @@ _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr _Tp bit_ceil(_Tp __t) noex } } -#endif // _LIBCPP_STD_VER >= 20 +# if _LIBCPP_STD_VER >= 20 + +template <__libcpp_unsigned_integer _Tp> +_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr _Tp bit_ceil(_Tp __t) noexcept { + return std::__bit_ceil(__t); +} + +# endif // _LIBCPP_STD_VER >= 20 +#endif // _LIBCPP_STD_VER >= 17 _LIBCPP_END_NAMESPACE_STD diff --git a/contrib/libs/cxxsupp/libcxx/include/__bit/countl.h b/contrib/libs/cxxsupp/libcxx/include/__bit/countl.h index 5d5744ac9a..23a7c42773 100644 --- a/contrib/libs/cxxsupp/libcxx/include/__bit/countl.h +++ b/contrib/libs/cxxsupp/libcxx/include/__bit/countl.h @@ -74,7 +74,7 @@ int __countl_zero(_Tp __t) _NOEXCEPT int __iter = 0; const unsigned int __ulldigits = numeric_limits<unsigned long long>::digits; while (true) { - __t = std::__rotr(__t, __ulldigits); + __t = std::__rotl(__t, __ulldigits); if ((__iter = std::__countl_zero(static_cast<unsigned long long>(__t))) != __ulldigits) break; __ret += __iter; diff --git a/contrib/libs/cxxsupp/libcxx/include/__bit/invert_if.h b/contrib/libs/cxxsupp/libcxx/include/__bit/invert_if.h new file mode 100644 index 0000000000..f7606ede26 --- /dev/null +++ b/contrib/libs/cxxsupp/libcxx/include/__bit/invert_if.h @@ -0,0 +1,30 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP___BIT_INVERT_IF_H +#define _LIBCPP___BIT_INVERT_IF_H + +#include <__concepts/arithmetic.h> +#include <__config> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +template <bool _Invert, class _Tp> +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Tp __invert_if(_Tp __v) { + if (_Invert) + return ~__v; + return __v; +} + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP___BIT_INVERT_IF_H diff --git a/contrib/libs/cxxsupp/libcxx/include/__bit/rotate.h b/contrib/libs/cxxsupp/libcxx/include/__bit/rotate.h index e9f4c8d474..d848056c33 100644 --- a/contrib/libs/cxxsupp/libcxx/include/__bit/rotate.h +++ b/contrib/libs/cxxsupp/libcxx/include/__bit/rotate.h @@ -20,29 +20,35 @@ _LIBCPP_BEGIN_NAMESPACE_STD -template<class _Tp> -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 -_Tp __rotr(_Tp __t, unsigned int __cnt) _NOEXCEPT -{ - static_assert(__libcpp_is_unsigned_integer<_Tp>::value, "__rotr requires an unsigned integer type"); - const unsigned int __dig = numeric_limits<_Tp>::digits; - if ((__cnt % __dig) == 0) - return __t; - return (__t >> (__cnt % __dig)) | (__t << (__dig - (__cnt % __dig))); +template <class _Tp> +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Tp __rotr(_Tp __t, int __cnt) _NOEXCEPT { + static_assert(__libcpp_is_unsigned_integer<_Tp>::value, "__rotr requires an unsigned integer type"); + const unsigned int __dig = numeric_limits<_Tp>::digits; + if ((__cnt % __dig) == 0) + return __t; + + if (__cnt < 0) { + __cnt *= -1; + return (__t << (__cnt % __dig)) | (__t >> (__dig - (__cnt % __dig))); // rotr with negative __cnt is similar to rotl + } + + return (__t >> (__cnt % __dig)) | (__t << (__dig - (__cnt % __dig))); +} + +template <class _Tp> +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Tp __rotl(_Tp __t, int __cnt) _NOEXCEPT { + return std::__rotr(__t, -__cnt); } #if _LIBCPP_STD_VER >= 20 template <__libcpp_unsigned_integer _Tp> -[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _Tp rotl(_Tp __t, unsigned int __cnt) noexcept { - const unsigned int __dig = numeric_limits<_Tp>::digits; - if ((__cnt % __dig) == 0) - return __t; - return (__t << (__cnt % __dig)) | (__t >> (__dig - (__cnt % __dig))); +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _Tp rotl(_Tp __t, int __cnt) noexcept { + return std::__rotl(__t, __cnt); } template <__libcpp_unsigned_integer _Tp> -[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _Tp rotr(_Tp __t, unsigned int __cnt) noexcept { +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _Tp rotr(_Tp __t, int __cnt) noexcept { return std::__rotr(__t, __cnt); } |