From d74285c13bfb459e9b315a04242cc779ad7891e7 Mon Sep 17 00:00:00 2001 From: Bernhard Manfred Gruber Date: Mon, 2 Dec 2024 08:47:55 +0100 Subject: [PATCH 1/3] Avoid checking unsigned values for negativity --- cub/cub/detail/fast_modulo_division.cuh | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/cub/cub/detail/fast_modulo_division.cuh b/cub/cub/detail/fast_modulo_division.cuh index d58a940abc9..a049f0b2d40 100644 --- a/cub/cub/detail/fast_modulo_division.cuh +++ b/cub/cub/detail/fast_modulo_division.cuh @@ -109,11 +109,14 @@ multiply_extract_higher_bits(T value, R multiplier) { static_assert(supported_integral::value, "unsupported type"); static_assert(supported_integral::value, "unsupported type"); - _CCCL_DIAG_PUSH - _CCCL_DIAG_SUPPRESS_ICC(186) // pointless comparison of unsigned integer with zero - _CCCL_ASSERT(value >= 0, "value must be non-negative"); - _CCCL_ASSERT(multiplier >= 0, "multiplier must be non-negative"); - _CCCL_DIAG_POP + _CCCL_IF_CONSTEXPR (_CCCL_TRAIT(is_signed, T)) + { + _CCCL_DIAG_PUSH + _CCCL_DIAG_SUPPRESS_ICC(186) // pointless comparison of unsigned integer with zero + _CCCL_ASSERT(value >= 0, "value must be non-negative"); + _CCCL_ASSERT(multiplier >= 0, "multiplier must be non-negative"); + _CCCL_DIAG_POP + } static constexpr int NumBits = sizeof(DivisorType) * CHAR_BIT; using unsigned_t = unsigned_implicit_prom_t; using larger_t = larger_unsigned_type_t; From e14774f77ee496195cc01c2aa770476ae1b10a6a Mon Sep 17 00:00:00 2001 From: Bernhard Manfred Gruber Date: Mon, 2 Dec 2024 15:28:03 +0100 Subject: [PATCH 2/3] Update cub/cub/detail/fast_modulo_division.cuh Co-authored-by: Michael Schellenberger Costa --- cub/cub/detail/fast_modulo_division.cuh | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/cub/cub/detail/fast_modulo_division.cuh b/cub/cub/detail/fast_modulo_division.cuh index a049f0b2d40..f41cf75b6f4 100644 --- a/cub/cub/detail/fast_modulo_division.cuh +++ b/cub/cub/detail/fast_modulo_division.cuh @@ -109,14 +109,17 @@ multiply_extract_higher_bits(T value, R multiplier) { static_assert(supported_integral::value, "unsupported type"); static_assert(supported_integral::value, "unsupported type"); + _CCCL_DIAG_PUSH + _CCCL_DIAG_SUPPRESS_ICC(186) // pointless comparison of unsigned integer with zero _CCCL_IF_CONSTEXPR (_CCCL_TRAIT(is_signed, T)) { - _CCCL_DIAG_PUSH - _CCCL_DIAG_SUPPRESS_ICC(186) // pointless comparison of unsigned integer with zero _CCCL_ASSERT(value >= 0, "value must be non-negative"); + } + _CCCL_IF_CONSTEXPR (_CCCL_TRAIT(is_signed, R)) + { _CCCL_ASSERT(multiplier >= 0, "multiplier must be non-negative"); - _CCCL_DIAG_POP } + _CCCL_DIAG_POP static constexpr int NumBits = sizeof(DivisorType) * CHAR_BIT; using unsigned_t = unsigned_implicit_prom_t; using larger_t = larger_unsigned_type_t; From ff0334ed8cfacebdbd9af17a677667aa1095101a Mon Sep 17 00:00:00 2001 From: Bernhard Manfred Gruber Date: Mon, 2 Dec 2024 15:37:06 +0100 Subject: [PATCH 3/3] Fix namespace --- cub/cub/detail/fast_modulo_division.cuh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cub/cub/detail/fast_modulo_division.cuh b/cub/cub/detail/fast_modulo_division.cuh index f41cf75b6f4..2ae65400e71 100644 --- a/cub/cub/detail/fast_modulo_division.cuh +++ b/cub/cub/detail/fast_modulo_division.cuh @@ -111,11 +111,11 @@ multiply_extract_higher_bits(T value, R multiplier) static_assert(supported_integral::value, "unsupported type"); _CCCL_DIAG_PUSH _CCCL_DIAG_SUPPRESS_ICC(186) // pointless comparison of unsigned integer with zero - _CCCL_IF_CONSTEXPR (_CCCL_TRAIT(is_signed, T)) + _CCCL_IF_CONSTEXPR (_CCCL_TRAIT(::cuda::std::is_signed, T)) { _CCCL_ASSERT(value >= 0, "value must be non-negative"); } - _CCCL_IF_CONSTEXPR (_CCCL_TRAIT(is_signed, R)) + _CCCL_IF_CONSTEXPR (_CCCL_TRAIT(::cuda::std::is_signed, R)) { _CCCL_ASSERT(multiplier >= 0, "multiplier must be non-negative"); }