Skip to content

Commit

Permalink
use concept-like macro
Browse files Browse the repository at this point in the history
  • Loading branch information
fbusato committed Jan 9, 2025
1 parent 3c05cd5 commit 5a6fd4b
Showing 1 changed file with 23 additions and 27 deletions.
50 changes: 23 additions & 27 deletions libcudacxx/include/cuda/std/__bit/rotate.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
//
//===----------------------------------------------------------------------===//

Expand All @@ -21,69 +21,65 @@
# pragma system_header
#endif // no system header

#include <cuda/std/__type_traits/enable_if.h>
#include <cuda/std/__concepts/concept_macros.h>
#include <cuda/std/__type_traits/is_constant_evaluated.h>
#include <cuda/std/__type_traits/is_unsigned_integer.h>
#include <cuda/std/limits>

_LIBCUDACXX_BEGIN_NAMESPACE_STD

namespace __detail
{

template <class _Tp>
_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 <class _Tp>
_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 <class _Tp>
_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 <class _Tp>
_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 <class _Tp>
_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 <class _Tp>
_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
Expand Down

0 comments on commit 5a6fd4b

Please sign in to comment.