From 5a6fd4bb940f51a62a4dc4c65861c16589d3b8ac Mon Sep 17 00:00:00 2001 From: fbusato Date: Thu, 9 Jan 2025 23:23:10 +0000 Subject: [PATCH] use concept-like macro --- libcudacxx/include/cuda/std/__bit/rotate.h | 50 ++++++++++------------ 1 file changed, 23 insertions(+), 27 deletions(-) diff --git a/libcudacxx/include/cuda/std/__bit/rotate.h b/libcudacxx/include/cuda/std/__bit/rotate.h index b7571cae0b1..6d1cdf0ae58 100644 --- a/libcudacxx/include/cuda/std/__bit/rotate.h +++ b/libcudacxx/include/cuda/std/__bit/rotate.h @@ -4,7 +4,7 @@ // 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 -// SPDX-FileCopyrightText: Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES. +// SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. // //===----------------------------------------------------------------------===// @@ -21,69 +21,65 @@ # pragma system_header #endif // no system header -#include +#include +#include #include #include _LIBCUDACXX_BEGIN_NAMESPACE_STD -namespace __detail -{ - template -_CCCL_NODISCARD _LIBCUDACXX_HIDE_FROM_ABI constexpr _Tp __rotl_impl(_Tp __t, unsigned __cnt_mod) noexcept +_CCCL_NODISCARD _LIBCUDACXX_HIDE_FROM_ABI constexpr _Tp __rotl_impl(_Tp __t, uint32_t __cnt_mod) noexcept { return (__t << __cnt_mod) | (__t >> (numeric_limits<_Tp>::digits - __cnt_mod)); } template -_CCCL_NODISCARD _LIBCUDACXX_HIDE_FROM_ABI constexpr _Tp __rotr_impl(_Tp __t, unsigned __cnt_mod) noexcept +_CCCL_NODISCARD _LIBCUDACXX_HIDE_FROM_ABI constexpr _Tp __rotr_impl(_Tp __t, uint32_t __cnt_mod) noexcept { return (__t >> __cnt_mod) | (__t << (numeric_limits<_Tp>::digits - __cnt_mod)); } template -_CCCL_NODISCARD _LIBCUDACXX_HIDE_FROM_ABI constexpr _Tp __rotl(_Tp __t, unsigned __cnt) noexcept +_CCCL_NODISCARD _LIBCUDACXX_HIDE_FROM_ABI constexpr _Tp __rotl(_Tp __t, uint32_t __cnt) noexcept { - static_assert(__cccl_is_unsigned_integer<_Tp>::value, "__rotl requires unsigned"); + static_assert(__cccl_is_unsigned_integer<_Tp>::value, "__rotl requires unsigned types"); using __nlt = numeric_limits<_Tp>; - if (!__cccl_default_is_constant_evaluated() && sizeof(_Tp) <= sizeof(uint32_t)) + if (!_CUDA_VSTD::is_constant_evaluated() && sizeof(_Tp) <= sizeof(uint32_t)) { NV_IF_ELSE_TARGET(NV_IS_DEVICE, (return ::__funnelshift_l(__t, __t, __cnt);), // - (return _CUDA_VSTD::__detail::__rotl_impl(__t, __cnt % __nlt::digits);)) + (return _CUDA_VSTD::__rotl_impl(__t, __cnt % __nlt::digits);)) } - return _CUDA_VSTD::__detail::__rotl_impl(__t, __cnt % __nlt::digits); + return _CUDA_VSTD::__rotl_impl(__t, __cnt % __nlt::digits); } template -_CCCL_NODISCARD _LIBCUDACXX_HIDE_FROM_ABI constexpr _Tp __rotr(_Tp __t, unsigned __cnt) noexcept +_CCCL_NODISCARD _LIBCUDACXX_HIDE_FROM_ABI constexpr _Tp __rotr(_Tp __t, uint32_t __cnt) noexcept { - static_assert(__cccl_is_unsigned_integer<_Tp>::value, "__rotr requires unsigned"); + static_assert(__cccl_is_unsigned_integer<_Tp>::value, "__rotr requires unsigned types"); using __nlt = numeric_limits<_Tp>; - if (!__cccl_default_is_constant_evaluated() && sizeof(_Tp) <= sizeof(uint32_t)) + if (!_CUDA_VSTD::is_constant_evaluated() && sizeof(_Tp) <= sizeof(uint32_t)) { NV_IF_ELSE_TARGET(NV_IS_DEVICE, (return ::__funnelshift_r(__t, __t, __cnt);), // - (return _CUDA_VSTD::__detail::__rotr_impl(__t, __cnt % __nlt::digits);)) + (return _CUDA_VSTD::__rotr_impl(__t, __cnt % __nlt::digits);)) } - return _CUDA_VSTD::__detail::__rotr_impl(__t, __cnt % __nlt::digits); + return _CUDA_VSTD::__rotr_impl(__t, __cnt % __nlt::digits); } -} // namespace __detail - -template -_CCCL_NODISCARD _LIBCUDACXX_HIDE_FROM_ABI constexpr enable_if_t<__cccl_is_unsigned_integer<_Tp>::value, _Tp> -rotl(_Tp __t, unsigned __cnt) noexcept +_CCCL_TEMPLATE(class _Tp) +_CCCL_REQUIRES(_CCCL_TRAIT(_CUDA_VSTD::__cccl_is_unsigned_integer, _Tp)) +_CCCL_NODISCARD _LIBCUDACXX_HIDE_FROM_ABI constexpr _Tp rotl(_Tp __t, uint32_t __cnt) noexcept { - return _CUDA_VSTD::__detail::__rotl(__t, __cnt); + return _CUDA_VSTD::__rotl(__t, __cnt); } -template -_CCCL_NODISCARD _LIBCUDACXX_HIDE_FROM_ABI constexpr enable_if_t<__cccl_is_unsigned_integer<_Tp>::value, _Tp> -rotr(_Tp __t, unsigned __cnt) noexcept +_CCCL_TEMPLATE(class _Tp) +_CCCL_REQUIRES(_CCCL_TRAIT(_CUDA_VSTD::__cccl_is_unsigned_integer, _Tp)) +_CCCL_NODISCARD _LIBCUDACXX_HIDE_FROM_ABI constexpr _Tp rotr(_Tp __t, uint32_t __cnt) noexcept { - return _CUDA_VSTD::__detail::__rotr(__t, __cnt); + return _CUDA_VSTD::__rotr(__t, __cnt); } _LIBCUDACXX_END_NAMESPACE_STD